Changing format for currency


#1

Can you please tell me what I have to change to this line:

$[[ Math.floor(This.text.replace(’$’ , ‘’).replace(’,’ , ‘’)).toLocaleString() ]].[[(This.text.replace(’$’ , ‘’).replace(’,’ , ‘’)*1).toFixed(2).slice(-2)]]

…to make it work for a change from 1000.99 € to 1.000,99 €

Thank you


Currency Formatting!
#2

Hi!

You’ll have to provide a country abbreviation in toLocaleString() as that defaults to US otherwise. (I chose Spain since they use your desired format.) There are several other small things to change. This worked in my testing:

[[ Math.floor(This.text.replace('€' , '').replace('.' , '').replace(',', '.')).toLocaleString('ES') ]],[[(This.text.replace('€' , '').replace('.' , '').replace(',', '.')*1).toFixed(2).slice(-2)]] €

format-currency.rp (46.6 KB)


#3

Thanks for your reply, I have only one more problem and I’m too new to variables to solve it.

I have a global variable that is called [[Gesamtpreis]] how is the correct syntax to make this change to the value of that variable?

Sry for that stupid question.


#4

Hi!

No problem. Just replace This.text with Gesamtpreis in both places. Don’t put brackets around Gesamtpreis.


#5

OH WHAT? That’s wat I exactly did, but only for the first one and not the second.

A Product Owner was asking for such small detail inside my prototype for a big e-commerce relaunch. You helped me so much, I appreciate it. Thank you so much.


#6

Sorry, can you help me a last time, please?

I tried your file again and I think I feel confused. Maybe I made a mistake yesterday and thought it works.
I typed into the input 1000.98 € but I get 100.098,00 € as a result.

I don’t spot the mistake.

PS: I probably set my variable Gesamtpreis to 1000,98 (with comma) that’s why it worked…but not to 1000.98( with dot)


#7

Hi zzipz!

Can you post your fie? If so, be sure to point out where exactly the code in question is.


#8

Hi,

I made it work with a function you have posted somewhere here on the forum. So it works for the “green price” in the file, but not for the “red” onces. I would like to calculate the half price and round it to two digits behind the comma + replace the dot

replace.rp (888.8 KB)

Thank you


closed #9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.