WordPress.org

Forums

Calculated Fields Form
[resolved] Float type problem (3 posts)

  1. vasilybodnarchuk
    Member
    Posted 1 year ago #

    Hello. I have problem with calculating float variables.

    Sample:

    float a = 5.2;
    float result = a*a;

    So result = 27.040000000000003!!!!
    How to fix it?

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

  2. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    It is a common issue with javascript engine and the mathematical operations with float numbers, to solve the issue use the operation "prec"

    for example if "a" is fieldname1 (to use the same fields' names in "Calculated Fields Form"), the equation would be:

    prec(fieldname1*fieldname1,2)

    If fieldname1 has the value 5.2 the operation result would be 27.04

    Now, if you want a more precise result, use a bigger number as second parameter of "prec" operation, for example in:

    prec(fieldname1*fieldname1,4)

    the operation result would be 27.0400

  3. vasilybodnarchuk
    Member
    Posted 1 year ago #

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Calculated Fields Form
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic