Home Forums Bug Reporting Wrong calculation results

This topic contains 2 replies, has 2 voices, and was last updated by  Phoxounet 2 days, 14 hours ago.

  • Author
    Posts
  • #2617

    Phoxounet
    Participant

    Hi there,

    I know that TTC is not developped anymore but maybe someone could have an answer for me. I made a calculated combat sheet : it calculates damages based on protection and roll results. Anyway, i have some weird results : I sometimes get a xx,000000000001 ou yy,9999999999999 instead of the good result. Like 55*1,65 = 90.750000001 instead of 90.75. Any idea ?

  • #2619

    carl
    Keymaster

    It looks like floating-point imprecision. You should be able to fix this with the javascript function toFixed(). If the variable is named “damage,” for example, you would use

    damage = damage.toFixed(2);

    You can also use a “+” prefix to use only the number of digits necessary. If the result was 0.70 then

    damage = +damage.toFixed(2);

    will return 0.7.

  • #2620

    Phoxounet
    Participant

    Worked like a charm ! Thx a lot

You must be logged in to reply to this topic.