# Random Decimal Generator

**URL:** https://cl.desmos.com/t/random-decimal-generator/2540
**Category:** Questions
**Created:** [February 2, 2021, 8:11pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540 "2021-02-02T20:11:05Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Faith\_Biggs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/faith_biggs/32/2062_2.png) [@Faith\_Biggs](https://cl.desmos.com/u/Faith_Biggs)
#### Post date: [February 2, 2021, 8:11pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540/1 "2021-02-02T20:11:05Z")

</div>

I am wanting to code my note to where students can add two separate decimals, and I want them to be able to answer a series of these in one desmos slide. I know the code:  
r =randomGenerator()  
a = r.float(0,100)  
b = r.float(0,100)

However, I want the decimals to be between one to three decimal places.

---

<div class="post-metadata">

### Author: ![cwinske](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cwinske/32/3106_2.png) [@cwinske](https://cl.desmos.com/u/cwinske)
#### Post date: [February 2, 2021, 8:36pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540/2 "2021-02-02T20:36:23Z")

</div>

This takes your floating value and rounds to 3 decimal places.

```auto
a = numericValue("\operatorname{round}(${r.float(0,100)},3)")

```

---

<div class="post-metadata">

### Author: ![Faith\_Biggs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/faith_biggs/32/2062_2.png) [@Faith\_Biggs](https://cl.desmos.com/u/Faith_Biggs)
#### Post date: [February 4, 2021, 8:25pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540/3 "2021-02-04T20:25:10Z")

</div>

This did not work when I tried it. In the notes (in the student preview) it is displaying “\operatorname{round}[decimal here],3”

---

<div class="post-metadata">

### Author: ![Faith\_Biggs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/faith_biggs/32/2062_2.png) [@Faith\_Biggs](https://cl.desmos.com/u/Faith_Biggs)
#### Post date: [February 4, 2021, 8:26pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540/4 "2021-02-04T20:26:08Z")

</div>

Then, when I put the numericValue in front of that, in the student preview, it said “undefined”

---

<div class="post-metadata">

### Author: ![cwinske](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cwinske/32/3106_2.png) [@cwinske](https://cl.desmos.com/u/cwinske)
#### Post date: [February 4, 2021, 10:29pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540/5 "2021-02-04T22:29:51Z")

</div>

Did you make sure to include the `r=randomGenerator()` part?

---

<div class="post-metadata">

### Author: ![Faith\_Biggs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/faith_biggs/32/2062_2.png) [@Faith\_Biggs](https://cl.desmos.com/u/Faith_Biggs)
#### Post date: [February 5, 2021, 2:44pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540/6 "2021-02-05T14:44:39Z")

</div>

Yes I did! I am wondering if I should put r.int instead of r.float?

---

<div class="post-metadata">

### Author: ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)
#### Post date: [February 5, 2021, 6:25pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540/7 "2021-02-05T18:25:17Z")

</div>

Are you missing the parentheses around `[decimal here],3`?

---

<div class="post-metadata">

### Author: ![Cheryl](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cheryl/32/4044_2.png) [@Cheryl](https://cl.desmos.com/u/Cheryl)
#### Post date: [May 23, 2021, 6:32pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540/8 "2021-05-23T18:32:38Z")

</div>

I’m trying to do something similar - generate small random numbers for students to write in scientific notation. I thought the rounding might eliminate some of the digits, but it’s not working. Here’s the code I’m using:  
r = randomGenerator(button.pressCount)  
a = r.float(0,0.1)  
`rounded_value=numericValue("\\round(${a},5)") content: "`${a}`"`

---

<div class="post-metadata">

### Author: ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)
#### Post date: [May 24, 2021, 3:39am UTC](https://cl.desmos.com/t/random-decimal-generator/2540/9 "2021-05-24T03:39:12Z")

</div>

Your content is the unrounded “a”. Try using “rounded\_value” instead.

---

<div class="post-metadata">

### Author: ![Cheryl](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cheryl/32/4044_2.png) [@Cheryl](https://cl.desmos.com/u/Cheryl)
#### Post date: [May 24, 2021, 4:02am UTC](https://cl.desmos.com/t/random-decimal-generator/2540/10 "2021-05-24T04:02:29Z")

</div>

Yes, it worked beautifully. Thank you, so much!

---

<div class="post-metadata">

### Author: ![ARobo](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/arobo/32/3567_2.png) [@ARobo](https://cl.desmos.com/u/ARobo)
#### Post date: [November 13, 2022, 9:56pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540/11 "2022-11-13T21:56:47Z")

</div>

This biggest issue I can’t solve is forcing the output to display the hundreds place value when happens to be a 0. The most obvious application of this would be in displaying currency values. This has been confusing my newer students who are puzzled when I’m like "if there’s only one digit after the decimal point, add a zero. It’s a cool natural lesson LOL but overall it’s just annoying.

Please help! Here is my code:

a = numericValue(“\operatorname{round}(${r.float(2,4)},2)”)

---

<div class="post-metadata">

### Author: ![Sian\_Sleight](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sian_sleight/32/1592_2.png) [@Sian\_Sleight](https://cl.desmos.com/u/Sian_Sleight)
#### Post date: [November 24, 2022, 6:41pm UTC](https://cl.desmos.com/t/random-decimal-generator/2540/12 "2022-11-24T18:41:14Z")

</div>

It’s been so long since I worked on activities involving percent application that I can’t remember who to credit for this workaround, but I think this is what you are looking for?

```auto
decimal=numericValue("\\operatorname{round}\\left(${r.float(5,200)},3\\right)")
dollar=numericValue("\\operatorname{round}\\left(${decimal},2\\right)")

Format = 
"$${money}"

a0=numericValue("\round(${dollar},0)")
a1=numericValue("\round(${dollar},1)")
a2=numericValue("\round(${dollar},2)")

#This checks to see if the rounded values a0, a1 & a2 would ever display in the same way. 
#For whole numbers a0=a1 and a1=a2 so you manually add 2 zeros
#For numbers with a non zero first dp and a zero in the second dp a1=a2 so you manually add a zero to the content

money= when a0=a1 and a1=a2 "${a0}.00"
when a1=a2 "${a1}0"
otherwise "${a2}"

```
