ereg: ? 1234.56 ==> ? 1.234,56

Q

Quarco

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
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed,
9 Feb 2005 10:29:39, seen in Quarco
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.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed, 9
Feb 2005 13:31:17, seen in Paul R
For thousand separators, there's a reasonable-looking solution at
https://lists.latech.edu/pipermail/javascript/2004-June/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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top