I am getting back a response to price like 2511
which is actually 25.11
, it didn't convert it in response. I want to add a .
to the last two digits of a number so that I can convert it into cents. How can I do that? when I try diving the number by 100, it didn't work for numbers which have 00 in the last of them, so for like 100
I want to convert it into 1.00
, it will give 1
when divided by 100.
Asked
Active
Viewed 23 times
0

Leith
- 135
- 10
-
`number.toFixed(2)` – Samuel Liew Jun 16 '22 at 06:20
-
@SamuelLiew, when I have number such as 1441, and I do .toFixed(2), its output, like 1441.00. I don't want it like that, I want something like 14.41 – Leith Jun 16 '22 at 06:26
-
@KScandrett, It didn't work either – Leith Jun 16 '22 at 06:28
-
@leith you need to divide it by 100 first. Then apply SamuelLiew's answer – K Scandrett Jun 16 '22 at 06:29
-
@KScandrett, how? can you please show a working solution – Leith Jun 16 '22 at 06:34
-
`let num = 100; console.log( (num / 100).toFixed(2) );` – K Scandrett Jun 16 '22 at 12:24
-
or, `let num = 100; num = num/100; console.log( num.toFixed(2) );` etc – K Scandrett Jun 16 '22 at 12:27