Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap

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

You are here: irt.org | FAQ | JavaScript | Number | Q1503 [ previous next ]

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(','));

©2018 Martin Webb