Click to See Complete Forum and Search --> : A type "real" number


Vinnie Naydenov
05-20-2003, 03:26 PM
Hello everyone,

I have a silly little question, which will demostrate how new I am to JavaScript. Can anyone please tell me how I declare a variable in JavaScript which is type "real" or "float", whatever you want to call it. I would like to use it for dollar values. If there is a type "currency" or something similar out there, I would much rather use it, as long as it shows up to two decimal places. Thank you very much!

Vinnie

P.S. If I have to use "float" or "real", can you specify how I set it to show only up to 2 decimal places?

Jona
05-20-2003, 03:29 PM
http://javascript.internet.com/ has a script in their site that converts numbers to the currency format.

Charles
05-20-2003, 03:39 PM
<script type="text/javascript">
<!--

document.write('<p>', Math.PI.toFixed(2), '</p>')

// But older browsers don't know about the Number.toFixed() method so you might want to use:

document.write('<p>', Math.round(Math.PI * 100) / 100, '</p>');

// -->
</script>

Jona
05-20-2003, 03:41 PM
It's so simple! lol, that's neat Charles.