Math with Numeric Data in Coldfusion

I use a rule in Coldfusion to tab the values ​​of several input fields to make sure that they are 100. This works with integers, but the rule works if decimal numbers are entered, even when they are up to 100. I entered the total value in the message line, and a warning will be said: "These values ​​should be up to 100%, the current total of 100." Here is the code for the rule, as well as a screenshot showing the result at the entrance: 80, 18, 1.5, .1, .1 and .3

Screenshot: enter image description here

I don’t know what the problem is ...

<!--- Tabulate race --->
    <cfif isNumeric(form.whitePct)>
        <cfset race += #form.whitePct#>
    </cfif>
    <cfif isNumeric(form.blackPct)>
        <cfset race += #form.blackPct#>
    </cfif>
    <cfif isNumeric(form.asianPct)>
        <cfset race += #form.asianPct#>
    </cfif>
    <cfif isNumeric(form.paciPct)>
        <cfset race += #form.paciPct#>
    </cfif>
    <cfif isNumeric(form.amerIndPct)>
        <cfset race += #form.amerIndPct#>
    </cfif>
    <cfif isNumeric(form.othPct)>
        <cfset race += #form.othPct#>
    </cfif>

    <!--- Q60 - Numbers for this question should total 100% --->
    <cfif race neq '100'>
        <cfset queryAddRow(queryLog)>
        <cfset querySetCell(queryLog,"ruleField","whitePct")>
        <cfset querySetCell(queryLog,"ruleMessage","Q60 - Numbers for this question should total 100%, current total is #race#")>
        <cfset querySetCell(queryLog,"ruleGUID","A5DC7FDD-6624-4B0F-A99B-2589B8CBC07D")>
        <cfset querySetCell(queryLog,"ruleType","soft warning")>
        <cfset querySetCell(queryLog,"ruleCategory","RANGE")>
        <cfset querySetCell(queryLog,"ruleOrder","410")>
        <cfset querySetCell(queryLog,"ruleID","1484")>
    </cfif>

Edit: This problem seems to be specifically related to these numbers in that order. When I enter: .1, .1, .3, 1.5, 18, 80 - the rule does not work. Now I'm even more confused.

+4
1

, 100, "100". , .

, Floats. EQ NEQ. .

, 1%, 0,01,

<!--- Test for a race value of 100, given a tolerance of 0.01--->
<cfif abs(race-100.0) LT 0.01>

, 0,001,

<!--- Test for a race value of 100, given a tolerance of 0.001--->
<cfif abs(race-100.0) LT 0.001>
+1

Source: https://habr.com/ru/post/1671830/


All Articles