# WordPress.org

## Calculated Fields Form[resolved] Round to the next 10 (9 posts)

1. flabrea
Member
Posted 2 years ago #

hi guys, what do i have to do if i want the result to be round up (always up) to the next 10.

So if the result is 1.432, i want to display 1.440?!

Thanks so much!

2. codepeople
Member
Plugin Author

Posted 2 years ago #

Hi,

The process is simple, suppose the name of field is "fieldname1", then the equation would be:

ceil(fieldname1/10)*10

in a step by step, using the number of demo:

ceil(1432/10)*10 = ceil(143.2)*10 = 144*10 = 1440

3. flabrea
Member
Posted 2 years ago #

thanks so much! i guess now it is gonna be complicated. how can i display that rounded number with 2 decimals? 1440.00? :) thanks!

4. codepeople
Member
Plugin Author

Posted 2 years ago #

Hi,

There is available an operation in the calculated fields, prec(x,y), where y determines the decimals numbers. In your particular case the equation would be:

prec(ceil(fieldname1/10)*10,2)

5. flabrea
Member
Posted 2 years ago #

That all worked out pretty good!

Now what does the equation look like if i want to round to the first tenth after the decimal? Like 30.28 to 30.30?

`fieldname90*0.16+fieldname92`

All i get is 31.00 from 30.28?! Thanks for your help!

6. codepeople
Member
Plugin Author

Posted 2 years ago #

Hi,

Follow a similar logic using mathematical expressions:

if you have 30.28, and you want 30.30

prec(ceil(30.28*10)/10,2)

It is simple. I will develop the equation, step by step:

prec(ceil(30.28*10)/10,2) = prec(ceil(302.8)/10,2) = prec(303/10,2) = prec(30.3,2) = 30.30

prec(ceil((fieldname90*0.16+fieldname92)*10)/10,2)

That's all.
Best regards.

7. flabrea
Member
Posted 2 years ago #

thanks. works perfect!

8. flabrea
Member
Posted 2 years ago #

looks like i am really to stupid to this myself.

how can i transform 543,04 into 544,00? my experiments do not work ;(

9. codepeople
Member
Plugin Author

Posted 2 years ago #

Hi,

Exactly in the same way:

prec(ceil(543.04),2)

Best regards.

This topic has been closed to new replies.