473,513 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ereg: ? 1234.56 ==> ? 1.234,56

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 3719
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2336
by: Stefan Gangefors | last post by:
I'm trying to figure out what I'm doing wrong when using ereg(). This is my regexp: ereg("^]$", "]"); and that does'n work, but this does: ereg("^$", "[");
9
2402
by: Fiore Alessandro | last post by:
Hi all I've installed Apache 2.0.48 and PHP 4.3.4 on a workstation running Linux, RedHat 9.0. Let's consider the following piece of code: $patt = "{3}/{6}"; if...
3
20968
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
2
4439
by: pomho | last post by:
Hi all, Even having read the PHP Manual, I can't understand the difference between the ereg function and the preg_match... Could anyone help ? thx in advance, --
3
2392
by: Rafal Zak | last post by:
I have a little problem with ereg (eregi) in PHP - in some cases it behaves differently than I expect and I don`t know if my expectations are strange or there is any "syntax subtlety" I have...
3
1601
by: Dynamo | last post by:
Hi, Thanks to all who replied to original posting.As a direct result of now gaining a better understanding of regular expressions, instead of trying to use other peoples scripts I am now trying to...
3
1591
by: news | last post by:
I'm trying to make sure a form has only one or two digits in either of two fields. I looked at php.net and http://www.regular-expressions.info/reference.html and this is what I put together, but...
3
2234
by: rachellara1979 | last post by:
Hi, new to PHP and to this group, so very sorry if this is simple or has been covered before. Basically want to check that a user and password (entered in a previous page) only has characters but...
18
2008
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
4
2066
by: penzer | last post by:
how to exchange 1234(number) -bytes sequence in the C#?
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.