rounding problem

Answered

Comments

13 comments

  • Stefan Ukena

    Hi Jan,

    this is just how floating point arithmetics work. See http://floating-point-gui.de/ for an explanation and ways around it.

    Best,
    Stefan

    dieKollaborateure.com - Podio Training+Consulting+Developmentauch auf Deutsch

    1
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Hi Jan,

    it's not a Podio problem. If you select "2 decimals" in the field options, it's only the option how many decimals should be shown. The number in the "background" which is used for the calculation is the full number with all decimals. So you have to fix the decimals with Javascript. You can try:

    kostennetto = +(((kostennetto + mwst)/0.01)*0.01).toFixed(2)
    

    Rainer

    1
    Comment actions Permalink
  • Jan Richter

    Thanks!
    @Stefan: The link is good knowledge. Didn't know.
    @Rainer: Works!
    Another workaround I found was toString & parseFloat. It's not that good, but it kinda also works.

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    .toFixed() does the same with a number as toString() (but sets decimals too), + in this case the same as parseFloat (converting it back to a number).

    0
    Comment actions Permalink
  • Jan Richter

    Ah ok, very nice!

    0
    Comment actions Permalink
  • John Trickett

    Jan,
    I am using .toFixed(2) in a calculation field to convert a currency field to text so that it displays the correct number of decimal places when exported to a word document using WebMerge.
    I don't have thousands separation anymore. Is there a workaround for this?
    Many Thanks,
    John.

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Hi John,

    I use this to get the thousand separator (,):

     Field.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
    

    Rainer
    rg@delos-consulting.com

    0
    Comment actions Permalink
  • John Trickett

    Perfect. Thank you!

    0
    Comment actions Permalink
  • Scott Anderson CCIM

    This worked perfectly for me.  

    kostennetto = +(((kostennetto + mwst)/0.01)*0.01).toFixed(2)

    Rainer you're amazing at this calculation stuff!  Thank you. 

    0
    Comment actions Permalink
  • James Graham

    The rounding solution is for users of Javascript only!! What would be the workaround within Podio's calculation field??

    James

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi James,

    everytime you enter something in a calculation field, you use Javascript. Calculation fields are based on Javascript.

    If you only add a token into a calculation field like

    @AVG of some field

    you can define the number of decimals in the feild settings (which rounds the result):

    Rainer
     

    0
    Comment actions Permalink
  • Hans Rudbeck Dahl

    Hello Guys & Podio, 

    My rounding problem is before,00 - I need to round the result up to nearest 5. I have used some of your java solutions before, and now I found 2 one at php.net and one on Stack Overflow, I can not get them to work.
    But then again, I know nothing about java or php. 

    I would appreciat any help, thanks 

     

    It says 

    float ceil ( float $value ) 

    ----

    <?php
    echo ceil(4.3);    // 5
    echo ceil(9.999);  // 10
    echo ceil(-3.14);  // -3
    ?>

    ----


    function
    round5(x) { return Math.ceil(x/5)*5; }

    -------------------

    Thanks for your help
    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Hans,

    PHP and Java solutions don't help cause the Podio calculation field uses JavaScript (and yes, Java and JavaSript are completly different things).

    If you want to round an integer to the nearest 5 (= round up or down)

    var val = 22;
    Math.round(val/5)*5 

    Result: 20

    If you want to round to the next 5 (= always round up)

    var val = 22;
    Math.ceil(val/5)*5

    Result 25

    A function you only need if you've many number values in your calculation and if you want to avoid  to enter the formula for each one 

    function round5(x)
    {
        return Math.ceil(x/5)*5;
    };
    round5(numberA) + round5(numberB) + round5(numberC)

    Rainer

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk