-2

I am new to JS and trying to remove the full stop from the returned number, I've managed to work out removing the thousand separator but not sure how to add to also remove the full stop. Anyone have any ideas?

JS

var total = parseFloat(a) + parseFloat(b);
total = parseFloat(Math.round(total * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
total = total.replace(/\,/g,'');
var newTotal = Shopify.formatMoney(total, '{{ shop.money_format }}');

Currently returns:

5977.00

But think I need to return it like

597700

So that the Shopify(formatMoney) function re-builds it.

halfer
  • 19,824
  • 17
  • 99
  • 186
James
  • 1,668
  • 19
  • 50
  • 1
    add the line: total = total.replace(/\./g,''); – Damien Black Mar 23 '16 at 21:55
  • Yea i assumed that, should i just add that after the /\, one or can i add both in that previous one? – James Mar 23 '16 at 21:56
  • You can do both at the same time with total.replace(/\.|\,/g,''); Look up "regular expressions" for more info. – Damien Black Mar 23 '16 at 21:57
  • Ahh perfect, i just tried add with another one so the amount was passed to the formatMoney function in shopify and displayed correctly and just done the merged one and worked a treat! thanks mate, if you want to make an Answer i will mark it :) thanks for your help! – James Mar 23 '16 at 21:59

2 Answers2

1

add the line: total = total.replace(/\./g,'');

Or, remove both the comma and the period at once with: total = total.replace(/\.|\,/g,'');

Look up 'regular expressions' for more info on how to create searches for specific patterns in text.

Damien Black
  • 5,579
  • 18
  • 24
0

You can use .split & .join like so:

total = total.split('.').join("");

Refer to this page here: removing dot symbol from a string

You can also use

Math.round(total)

or

parseInt(total);
Community
  • 1
  • 1
James111
  • 15,378
  • 15
  • 78
  • 121