By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,628 Members | 1,880 Online
Bytes IT Community
+ Ask a Question
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
Share this Question
Share on Google+
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
<do********@hotmail.com> posted :
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...)

Newsgroup FAQ, Sec 4.6, but with '.' changed to ','; then adapt from
<URL:http://www.merlyn.demon.co.uk/js-maths.htm#Out> to insert thousands
separators.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3

P: n/a
JRS: In article <Fg**************@newsfe4-gui.ntli.net>, dated Wed, 9
Feb 2005 13:31:17, seen in news:comp.lang.javascript, Paul R
<no*********@email.address> posted :
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


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
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> 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" <do********@hotmail.com> 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.