Is it possible to auto-format a number field in scriptrunner?
Ex:
Cap: 12.335 should be 12.34
Cap: 12.3 should be 12.30
Cap: 12 should be 12.00
Can you try this and let me know if this works?
def cap = 12.335
cap = ((float)cap).round(2)
println cap
Thanks,
Pramodh
how would i do that? would i need a text field vs number field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here it is @Scott Federman
Let me know if this works
def cap = 2.34
cap = ((float)cap).round(2)
cap = ((String)cap)
str = cap.split("\\.");
if (str[1].length() == 1)
cap = ((String)cap) + "0"
println cap
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pramodh M it returns this error "The scripted field ran successfully, but returned an invalid type. Please return a number" There is only a number in the field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you are returning a number, 2 zero after the decimal is not possible
You need to use this
def cap = 2.34
cap = ((float)cap).round(2)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Pramodh M i converted this to a text field called Cap-test. Changed the script to
def cap-test = 2.34
cap-test = ((float)cap-test).round(2)
cap-test = ((String)cap)
str = cap-test.split("\\.");
if (str[1].length() == 1)
cap-test = ((String)cap-test) + "0"
println cap-test
and returned this error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.