Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I move the decimal point to the 100ths of an integer?

This seems like a silly question but I cant figure out how to convert an integer number that represent cents to dollars.

3000 -> 30.00

in javascript...

I was using ParseFloat but it's only giving me back the integer =/ I need to always display the cents even if its 0.

like image 477
qodeninja Avatar asked Dec 10 '10 01:12

qodeninja


People also ask

How do u round to the hundredths place?

To round a number to the nearest hundredth, look at the digit at the right of the hundredth place and apply the same rule : if the digit in the thousandth place is 0, 1, 2, 3, 4, you will round down to the nearest hundredth or just remove all digits found at the right.

How do you write a decimal in the hundredths place?

The first digit after the decimal represents the tenths place. The next digit after the decimal represents the hundredths place.

Do you move the decimal to the left or right when multiplying?

The difference is that the decimal point moves to the right when you multiply; it moves to the left when you divide.


2 Answers

Use toFixed().

var num = 3000;

alert( (num/100).toFixed( 2 ) ); // alerts 30.00
like image 188
user113716 Avatar answered Oct 11 '22 12:10

user113716


Try something similar to:

document.write(x.toFixed(2));
like image 40
Drew D. Avatar answered Oct 11 '22 12:10

Drew D.