WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. flabrea
    Member
    Posted 9 months 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!

    http://wordpress.org/plugins/calculated-fields-form/

  2. codepeople
    Member
    Plugin Author

    Posted 9 months 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 9 months 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 8 months 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 6 months 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 6 months 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

    Replacing 30.28 by your equation:

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

    That's all.
    Best regards.

  7. flabrea
    Member
    Posted 6 months ago #

    thanks. works perfect!

  8. flabrea
    Member
    Posted 5 months 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 5 months ago #

    Hi,

    Exactly in the same way:

    prec(ceil(543.04),2)

    Best regards.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.