How do I remove a decimal place on Velocity Template

Sam Morris January 20, 2014

Hello

I've written an Velocity email Template. The following Number Field is displaying with a decimal place.

Incident Level: $issue.getCustomFieldValue("customfield_11513") is showing to one decimal place e.g. 4.0

How can I format this number to remove the decimal place. e.g. Just 4 instead of 4.0

?

Thanks

Sam

1 answer

1 accepted

4 votes
Answer accepted
Sam Morris June 29, 2014

Hi Guys,

I've worked this one out -
$issue.getCustomFieldValue("customfield_xxxxx").toString().replaceAll(".0", "")

Stephen Hayden
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.
October 6, 2015

Thanks for this!!

Stephen Hayden
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.
October 6, 2015

I wish I could get this working for Date Pickers... they're all suffixed with a 00:00:00.0.

Stephen Hayden
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.
October 7, 2015

I fixed this also, by first defining a variable, guessing I needed to escape the colons or something. #set( $notime = "00:00:00.0" ) $issue.getCustomFieldValue("customfield_xxxxx").toString().replaceAll($notime, "")

Dalectric
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.
July 2, 2016

Needed to make a small adjustment to escape the . so it didn't replace things like 80

replaceAll("\.0", "")
Tamas Balint November 13, 2020

I believe $number.format("#0","customfield_xxxxx") is better as the one above fails on two digits (e.g. 10.0) like it was using . as a single character wildcard. (I tried also 20.0)...

Like Dalectric likes this

Suggest an answer

Log in or Sign up to answer