You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation of the unformat function does not take into account that there are currency symbols that may contain the same character used for the decimal separator.
Please consider the Swedish Krona as an example. That currency uses kr as a currency symbol but most stores use the alternative kr. version (with a trailing dot).
Now, if you try to unformat kr. 123.45, this first replace call returns '.123.45'. When this string is passed to parseFloat, this is what you get:
constregex=newRegExp("[^0-9-"+decimal+"]",["g"]);letpriceString='kr. 123.45';priceString=priceString.replace(regex,'');// price string is now '.123.45'constresult=parseFloat(priceString);// result is .123 instead of the expected value of 123.45// because of the leading dot left from the currency symbol
The simplest approach to solve this issue is to pass the currency symbol to unformat so that it can be replaced before going ahead with any further string manipulation. The new function definition could be:
constunformat=function(value,decimal,symbol){symbol=symbol||lib.settings.currency.symbol;value=value.replaceAll(symbol,'');// the rest of the current implementation}
I hope this helps.
The text was updated successfully, but these errors were encountered:
The current implementation of the
unformat
function does not take into account that there are currency symbols that may contain the same character used for the decimal separator.Please consider the Swedish Krona as an example. That currency uses
kr
as a currency symbol but most stores use the alternativekr.
version (with a trailing dot).Now, if you try to unformat
kr. 123.45
, this firstreplace
call returns'.123.45'
. When this string is passed toparseFloat
, this is what you get:The simplest approach to solve this issue is to pass the currency symbol to unformat so that it can be replaced before going ahead with any further string manipulation. The new function definition could be:
I hope this helps.
The text was updated successfully, but these errors were encountered: