# Number Generation with a Decimal

**URL:** <https://community.postman.com/t/number-generation-with-a-decimal/17314>\
**Category:** Help Hub\
**Created:** [November 2, 2020, 3:06pm UTC](https://community.postman.com/t/number-generation-with-a-decimal/17314 "2020-11-02T15:06:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JBird20](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@JBird20](https://community.postman.com/u/JBird20)\
**Post date:** [November 2, 2020, 3:06pm UTC](https://community.postman.com/t/number-generation-with-a-decimal/17314/1 "2020-11-02T15:06:03Z")

</div>

Hi,

Could anyone advise me on how to get a random number between 1 - 50 with an additional 2 decimal numbers between 1 - 99?

e.g. so i could get 1.54 or 23.91

I can find examples of whole numbers, but nothing for items with decimals.

I’m sure there is a nicer way than:

const pounds = (“random\_number”, \_.random(1, 50));

const pence = (“random\_number”, \_.random(10, 99));

const paymentAmount = pounds + “.” + pence

Any help is appreciated, thank you

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 2, 2020, 3:23pm UTC](https://community.postman.com/t/number-generation-with-a-decimal/17314/2 "2020-11-02T15:23:03Z")

</div>

This should return a floating-point number but I’m not sure if that’s fixed to 2 decimal places.

```javascript
const pounds = _.random(1, 50, true)

```

[https://lodash.com/docs/4.17.15#random](https://lodash.com/docs/4.17.15#random)

You could fix it to 2 places by using `toFixed(2)`:

```javascript
const pounds = _.random(1, 50, true)

console.log(pounds.toFixed(2))

```

---

<div class="post-metadata">

**Author:** ![fabianoflorentino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/fabianoflorentino/32/33212_2.png) [@fabianoflorentino](https://community.postman.com/u/fabianoflorentino)\
**Post date:** [August 1, 2025, 7:28pm UTC](https://community.postman.com/t/number-generation-with-a-decimal/17314/3 "2025-08-01T19:28:07Z")

</div>

maybe can you use the {{$randomPrice}} function.

---

<div class="post-metadata">

**Author:** ![lunar-module-geolog1](https://avatars.discourse-cdn.com/v4/letter/l/e495f1/32.png) [@lunar-module-geolog1](https://community.postman.com/u/lunar-module-geolog1)\
**Post date:** [August 2, 2025, 5:44am UTC](https://community.postman.com/t/number-generation-with-a-decimal/17314/4 "2025-08-02T05:44:46Z")

</div>

You can simplify it using Lodash like this:

```javascript
const paymentAmount = _.round(_.random(1, 50, true), 2);

```

This gives you a random number between 1 and 50 with 2 decimals.
