Process Mapping Logo

Process Mapping - Forums

Sharing 19 years of knowledge and experience

 
Metastorm BPM forums
Sign up Latest Topics
 
 
 


Reply
  Author   Comment  
paulsiu

Senior Member
Registered:
Posts: 57
Reply with quote  #1 

I notice a strange problem when I use parsefloat Jscript to read a number off a field.

parseFloat("33000.05")   ---> 33000

but

parseFloat("33,000.05")  ---> 33

I think in places like France and probably in other countries, a comma is used instead of a period for the dollar/cent separator and period is used for thousand. One would expect that the localized browser would automatically specify the correct separator, but may be it's not that smart.

We don't have any non-US customers (or at least customer that would use a comma as a dollar/cent), but I am curious. How do you folks handle this? You can't just strip out the comma, since that would screw up people using commas/

Paul


0
mohnshine

Avatar / Picture

Senior Veteran
Registered:
Posts: 270
Reply with quote  #2 
This is not a problem.  Jscript/Javascript numbers do not have delimiters except for the decimal place holder.  All delimiters other than the decimal place holder should be removed before using parseFloat.

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseFloat

From above URL

parseFloat parses its argument, a string, and returns a floating point number. If it encounters a character other than a sign (+ or -), numeral (0-9), a decimal point, or an exponent, it returns the value up to that point and ignores that character and all succeeding characters. Leading and trailing spaces are allowed.


__________________
Your best practice does not conform with my best practice.
0
Jerome

Avatar / Picture

Guru
Registered:
Posts: 5,507
Reply with quote  #3 
But....

I have the bad feeling that a number field in Metastorm will return a string with the thousands delimiter as well. If it does, these will obviously then need to be removed, depending on the locale.


__________________
Post an example, and we will have a much better idea what the problem is. In about 90% of posts, the problem is one of communication. Examples bridge that gap.
0
paulsiu

Senior Member
Registered:
Posts: 57
Reply with quote  #4 
Thanks for the info!

I didn't realized ParseFloat only support decimals. I thought the routine would be localized to parse commas in certain locations.

Yes, the number field return thousand separators. I just added the following routine to remove the thousand:

mystringvariable.replace(/,/g, "")

For some reason, the first parameter shouldn't be in quotes. The /g is so we will remove more than one instances of comma (though that's unlikely since employees don't make a salary of over a million).

Paul
0
Jerome

Avatar / Picture

Guru
Registered:
Posts: 5,507
Reply with quote  #5 
Well, the thousands separator is really only cosmetic. The actual 'number' does not contain it as it is meaningless.

Quote:
Originally Posted by paulsiu
The /g is so we will remove more than one instances of comma (though that's unlikely since employees don't make a salary of over a million).
Well, you are obviously not working for the right company, then! ;-)

__________________
Post an example, and we will have a much better idea what the problem is. In about 90% of posts, the problem is one of communication. Examples bridge that gap.
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:


Create your own forum with Website Toolbox!