- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 08:57 AM
I have a currency field that stores a value in this format: 'USD;1234.05' so it's storing as a string.
I am splitting on ; to just get the number returned (as a string).
var amnt = newValue.split(/;/);
My question is now that the number is a string (in this case it is 1234.05), how do I convert it to a number and keep the decimal?
I have tried:
var str = '11,110.05';
gs.print('String: ' + str);
var strInt = parseInt(str);
gs.print('Int: ' + strInt);
var flt = parseFloat(str).toFixed(2);
gs.print('Float: ' + flt);
Which is returning
*** Script: String: 11,110.05
*** Script: Int: 11
*** Script: Float: 11.00
Int and Float are changing the number completely. I just need the exact number and decimal to come through so I can compare it to another number. In the real example I want 11,110.05 returned as a number so I can compare it to 5000 to see if it's greater than 5,000.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 10:01 AM
Not sure if it is supported in Portal (or Workspace), but in Platform UI (UI16/Polaris) GlideForm has a method to return the value as a Number:
g_form.getDecimalValue('<currency field name>');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 10:01 AM
Not sure if it is supported in Portal (or Workspace), but in Platform UI (UI16/Polaris) GlideForm has a method to return the value as a Number:
g_form.getDecimalValue('<currency field name>');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 10:02 AM
I'm assuming this a Client Script environment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 10:09 AM
As for the problem with the original solution: both parsers stop parsing at the 1st illegal character. Since JavaScript only recognizes the dot as decimal separator and does not use grouping characters, both will stop parsing before the comma grouping separator in your string.
You could make use of the global variables g_user_decimal_separator
and g_user_grouping_separator
to eliminat the latter and transform the former into dot to convert the number display value into a parse-able one, but I think using newValue
to extract the currency code and the above mentioned API to get the numeric value is simpler.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2022 12:42 PM
How would that work for
let fltStr = '1,200.11';
?