SOLVED

# Rounding numbers with velocity

Go to solution
Level 2

## Rounding numbers with velocity

I have some data coming in with decimals and I was hoping to round it with velocity. For example, I have some numbers coming in as 34.36 and would like it to show 34.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Level 10 - Community Moderator

## Re: Rounding numbers with velocity

Get yourself a proper number-rounder and use it:

``````#set( \$integerFormat = \$number.getNumberFormat("integer", \$convert.toLocale("en_US")) )
#set( \$void = \$integerFormat.setRoundingMode(\$field.in(\$integerFormat.getRoundingMode()).HALF_UP) )

(Assuming of course you meant arithmetic rounding.)

Level 10 - Community Moderator

## Re: Rounding numbers with velocity

Well, it’s not actually possible to stop multiple COs from being created. So you always want to loop over the list, even if 99.9999% of the time it has only one item in it.

Like so:

``````#set( \$integerFormat = \$number.getNumberFormat("integer", \$convert.toLocale("en_US")) )
#set( \$void = \$integerFormat.setRoundingMode(\$field.in(\$integerFormat.getRoundingMode()).HALF_UP) )
#if( !\$CustomObjectList.isEmpty() )
#foreach( \$object in \$CustomObjectList )
\${integerFormat.format(\$number.toNumber(\$object.YourField))}
#end
#end
``````

6 REPLIES 6
Level 10 - Community Moderator

## Re: Rounding numbers with velocity

Get yourself a proper number-rounder and use it:

``````#set( \$integerFormat = \$number.getNumberFormat("integer", \$convert.toLocale("en_US")) )
#set( \$void = \$integerFormat.setRoundingMode(\$field.in(\$integerFormat.getRoundingMode()).HALF_UP) )

(Assuming of course you meant arithmetic rounding.)

Level 2

## Re: Rounding numbers with velocity

This is great, thank you. If you don't mind can you telling me how I would incorporate my custom object field in this? I am receiving the number through a custom object field and need my token to round the integer and display in my email. Thank you!

Level 10 - Community Moderator

## Re: Rounding numbers with velocity

Well, a person can have multiple CO records. Do you want to output this single field (rounded) for each CO record?

Level 2

## Re: Rounding numbers with velocity

Yes, it's just one field that I need to have rounded. We don't create multiple custom object records, just update the fields.

Level 10 - Community Moderator

## Re: Rounding numbers with velocity

Well, it’s not actually possible to stop multiple COs from being created. So you always want to loop over the list, even if 99.9999% of the time it has only one item in it.

Like so:

``````#set( \$integerFormat = \$number.getNumberFormat("integer", \$convert.toLocale("en_US")) )
#set( \$void = \$integerFormat.setRoundingMode(\$field.in(\$integerFormat.getRoundingMode()).HALF_UP) )
#if( !\$CustomObjectList.isEmpty() )
#foreach( \$object in \$CustomObjectList )
\${integerFormat.format(\$number.toNumber(\$object.YourField))}
#end
#end
``````

Level 2

## Re: Rounding numbers with velocity

Thank you SO much! Looks like it working.