459,628 Members | 1,880 Online
Need help? Post your question and get tips & solutions from a community of 459,628 IT Pros & Developers. It's quick & easy.

# ereg: ? 1234.56 ==> ? 1.234,56

 P: n/a Hi javascript guru's : I have a form with calculations, but i want the numbers presented in a diffrent way: Is it possible to replace values like ? 120 to ? 12,00 and ? 345.9 to ? 345,90 The most ideal situation would be ? 1.234,56 with numbers > 1000, but perhaps that's too difficult... (PS: I need only the replace function, I know how to walk-through the span's where the numbers are in...) Thanx in advance, Marco Jul 23 '05 #1
4 Replies

 P: n/a For thousand separators, there's a reasonable-looking solution at https://lists.latech.edu/pipermail/j...ne/007875.html. For decimal point/comma: numStr.replace(/(\d)(\d{2})\$/,"\$1,\$2"); // make final two digits into a decimal and numStr.replace(/\./, ","); // replace dot with comma and possibly numStr.replace(/\.(\d)\$/, ",\$10"); // enforce 2 decimal places where now only one Look up the RegExp object in your favourite JS reference for details. Jul 23 '05 #2

 P: n/a JRS: In article <42***********************@news.xs4all.nl>, dated Wed, 9 Feb 2005 10:29:39, seen in news:comp.lang.javascript, Quarco posted : I have a form with calculations, but i want the numbers presented in adiffrent way:Is it possible to replace values like ? 120 to ? 12,00and ? 345.9 to ? 345,90The most ideal situation would be ? 1.234,56 with numbers > 1000, butperhaps that's too difficult...(PS: I need only the replace function, I know how to walk-through the span'swhere the numbers are in...) Newsgroup FAQ, Sec 4.6, but with '.' changed to ','; then adapt from to insert thousands separators. -- © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 © JL/RC: FAQ of news:comp.lang.javascript jscr maths, dates, sources. TP/BP/Delphi/jscr/&c, FAQ items, links. Jul 23 '05 #3

 P: n/a JRS: In article , dated Wed, 9 Feb 2005 13:31:17, seen in news:comp.lang.javascript, Paul R posted :For thousand separators, there's a reasonable-looking solution athttps://lists.latech.edu/pipermail/j...ne/007875.html.For decimal point/comma: numStr.replace(/(\d)(\d{2})\$/,"\$1,\$2"); // make final two digits into a decimaland numStr.replace(/\./, ","); // replace dot with commaand possibly numStr.replace(/\.(\d)\$/, ",\$10"); // enforce 2 decimal places where now only one You should test those on a reasonably wide range of numbers, including 0 and 0.07 and 17; and read the newsgroup FAQ. -- © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 © JL/RC: FAQ of news:comp.lang.javascript jscr maths, dates, sources. TP/BP/Delphi/jscr/&c, FAQ items, links. Jul 23 '05 #4

 P: n/a Thanx all for your time / replies !!! It works great! Regards from Holland, Marco "Quarco" schreef in bericht news:42***********************@news.xs4all.nl... Hi javascript guru's : I have a form with calculations, but i want the numbers presented in a diffrent way: Is it possible to replace values like ? 120 to ? 12,00 and ? 345.9 to ? 345,90 The most ideal situation would be ? 1.234,56 with numbers > 1000, but perhaps that's too difficult... (PS: I need only the replace function, I know how to walk-through the span's where the numbers are in...) Thanx in advance, Marco Jul 23 '05 #5

### This discussion thread is closed

Replies have been disabled for this discussion.