Link to home
Start Free TrialLog in
Avatar of eaweb
eawebFlag for undefined

asked on

replace   text in javascript

hi,

i using below code to format numbers
roundNumber(formatNumbers($number, 3), 2).toFixed(2);

the issue is that the $number can come as   which is breaking the script. how must i rewrite the code to to check if the $number contains the text   and if yes change it to 000 else use the value of $number?
Avatar of leakim971
leakim971
Flag of Guadeloupe image

roundNumber(formatNumbers($number.replace(/ /g,""), 3), 2).toFixed(2);
Avatar of eaweb

ASKER

when running the code i can get it as follow.
roundNumber(formatNumbers(1616161, 3), 2).toFixed(2);  --- ok
or
roundNumber(formatNumbers( , 3), 2).toFixed(2);  ---bad
we remove   each time
Avatar of eaweb

ASKER

this how i get it

roundNumber(formatNumbers(100000000.replace(/ /g,""), 3), 2).toFixed(2);

roundNumber(formatNumbers( .replace(/ /g,""), 3), 2).toFixed(2);
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it would be better(?) to put the "replace" inside your formatNumber function