Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1503 How do I round a number which is separated by commas to 2 decimal places, e.g. 10,987.9876 to 10987.98?

irt.org | Knowledge Base | JavaScript | Number | Q1503 [ previous next ]

Q1503 How do I round a number which is separated by commas to 2 decimal places, e.g. 10,987.9876 to 10987.98?

If there is a comma it is not a number but a string. Do this:

<script language="JavaScript"><!--
myNumber = parseFloat(myCommaNumber.split(',').join('.'));

and then use the round function in the number faq.
after that you reverse it:
myCommaNumber = "" round(myNumber);
myCommaNumber = myCommaNumber.split('.').join(','));
//--></script>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.