Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Change the format number in script field

Camille Lecerf
Contributor
January 30, 2019

Hi,

Could someone help me please? I would like to change the separators of my script field (number)

12,345.67 --> 12 345,67

How could I do this please? I think I have to write something here (in the Custom Script Field editor), but I don't know what:2019-01-30 14_08_49-Script Fields.png

 

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2019

You'll need to do the formatting in your code, then just put $value into the template (or change the template to text)

Camille Lecerf
Contributor
January 30, 2019

Hi Nic,

Thank you for your answer. Yet I don't know how to format it in the script... (I don't code)

Could you please tell me what to add in ?

Regards,

Camille

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2019

The format you've put in the question is not familiar to me, I'm used to seeing people ask for numbers to come out in their local language format (e.g. in English and US English, we have the format you are converting from, but in Spanish, you'd see 12.345,67)

If it is a valid format for a country (probably is), then

return NumberFormat(getNumberInstance(Locale.xx).format($number))

Would format it for the country named by the xx (US for USA, CH for Switzerland, GB for the UK, DE for Germany etc)

Camille Lecerf
Contributor
January 31, 2019

Thank you for your help. I added this at the top of my code

import java.text.NumberFormat

And that at the end:

def frenchnumber = NumberFormat.getCurrencyInstance(Locale.FRENCH).format($number);

return frenchnumber;

Yet, for 12,345.67I get 12 (what I expected was 12 354,67)

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2019

Hm.  What is actually in $number ?  Could you temporarily "return $number" at the bottom and hit preview to see it with the default java format?

Camille Lecerf
Contributor
January 31, 2019

"return $number" gives me 12,345.67 but I found the issue: this was just due to my profile settings set to English by default. Changing the language and choosing "Number" in the template of the script field solved the problem.

I did not noticed that before, this is the 1st time I use Number fields with big values :)

2019-01-31 20_21_33-Update User Preferences - iXblue.png

Thank you for your help Nic!

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2019

Ahh!  Well spotted!

Suggest an answer

Log in or Sign up to answer