ShowAll Questionssorted byDate Posted
Marcelo Agostinho

# Round a number

Hello. Again i'm here to make some questions.

I'm building an URL to send it ro Google Chart API and it will return an image.

What i need to do is get the maximum value of the Chart data and round up it to An integer...

For example...

If my maximum value is 2475.59 i want to convert it to a string and round up to 2500.

Can i do it?

Anyone can help me?

Tks

Best Answer chosen by Admin (Salesforce Developers)
sfdcfox

You'll need to figure out how much you want to round to, and then do the appropriate math. In your example, you might do:

`String roundedValue = String.valueOf(Math.round(preValue/100)*100);`

This would convert 2475.59 to 24.7559, then rounded to 25.0000, then multiplied back, becomes 2500.00. From there, String.valueOf takes care of the conversion from a number to a string value.

### All Answers

sfdcfox

You'll need to figure out how much you want to round to, and then do the appropriate math. In your example, you might do:

`String roundedValue = String.valueOf(Math.round(preValue/100)*100);`

This would convert 2475.59 to 24.7559, then rounded to 25.0000, then multiplied back, becomes 2500.00. From there, String.valueOf takes care of the conversion from a number to a string value.

This was selected as the best answer
Marcelo Agostinho

Very Tks to you sfdcfox its works perfectly