Forums

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

Show incorrect number in script field

Marzi Goodarzian
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.
September 11, 2021 edited

Hi

I used number field and recieved phone number from customer,and was shown like 123,456,789 in view screen, then I created script field and convert this number to 123456789.

But When this number end to 0, number shown like 123456789E+9!!

My script is:

import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;


def customFieldsManager = ComponentAccessor.getCustomFieldManager();
CustomField phoneNumber = (CustomField)customFieldsManager.getCustomFieldObject(14101);
if (phoneNumber == null )
return "";
String phoneNumberVal = issue.getCustomFieldValue(phoneNumber)
return phoneNumberVal.toBigDecimal().abs()

-->14101:FieldID

 

How fixed it?

1 answer

1 accepted

1 vote
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.
September 11, 2021

This E+ notation is the standard way to present numbers that are very large, and/or don't fit in fields.  It's a bit like saying "a one followed by twelve zeroes" instead of "a trillion"

There's nothing you can do about this directly, it's the way numeric fields are intended to work.

But.  A telephone number is not really a number, it is a strong (it's a series of instructions to "select each symbol in turn if you want to ring this person/place".  Another way to look at it is "outside 'magic' tricks, would you ever find dividing it by 4 useful?", or consider that spaces, +, ( and ) are valid in telephone numbers too - they're not numeric)

So there's a simple answer - use a string (short text) field for it instead.  These will not see the number as numeric and hence will not reformat it.

Marzi Goodarzian
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.
September 22, 2021

Hi @Nic Brough -Adaptavist- 

I used string field and for some number , the previous thing happens again(E+ notation).

How fix it completely?

Thanks alot

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.
September 25, 2021

String fields don't convert numbers to that format, they read everything as a string.  Of course, if you copy and paste an E-formatted number in, it will retain the E as a string.

But just putting plain characters into a string field won't convert (put some spaces in if you're unsure - 0207 123 4567 for example, can't ever be interpreted as a number by a string field)

Suggest an answer

Log in or Sign up to answer