• Resolved erictalv

    (@erictalv)


    Hello,

    I have my calculator setup as such:
    quantity_field_id_1
    quantity_field_id_2
    quantity_field_id_3
    quantity_field_id_4

    Now I have a total field with this formula:
    quantity_field_id_1 * quantity_field_id_2 * quantity_field_id_3 * quantity_field_id_4 / 1000

    This works as such BUT now I need to
    round the calculated value, so what I did was this:

    Math.round( quantity_field_id_1 * quantity_field_id_2 * quantity_field_id_3 * quantity_field_id_4 / 1000 )

    Which in theory should work, but for some reason gives an undrounded value.

    So, If my initial formula calculation gets this value: 3,742.20
    then upon rounding it I should get this: 3,74

    But I just get the same full value: 3,742.20

    I tried doing this:
    Math.round(3,742.20)
    this gives this: 3.00

    Which is somewhat close, but I ofcourse need it to square with the
    quantity fields not with a hardcoded value.

    How can I do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter erictalv

    (@erictalv)

    Hello,

    Turns out my math was wrong here, the round function didnt do what I needed and I also had my equation wrong.

    Basically I had to update my equation to this:
    (quantity_field_id_1 * quantity_field_id_2 * quantity_field_id_3 * quantity_field_id_4 / 1000) / 1000

    Which with these values:
    (297 * 210 * 60 * 1 / 1000 ) / 1000 = 3,7422

    And now I use the Math.abs to get the absolute value,
    so my end equation is this:

    Math.abs(quantity_field_id_1 * quantity_field_id_2 * quantity_field_id_3 * quantity_field_id_4 / 1000) / 1000

    Hi @erictalv

    We are glad that you resolved it on your own!

    Feel free to contact us in case of any other questions.

    regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Math.Round Is not Working as expected’ is closed to new replies.