Math

Finding Percentage

Let us take a look at a simple operation to find a percentage using the method of the Number object.

Example

Display the result of processing the percentage operation on the entered value. You can specify additional rounding options.

sample_math_01.xfdl

Core features used in the example

round

This is the method that returns the value rounded to the decimal point. In the example, the round method of the Math object and the round method provided by nexacroAPI are used. The round method of the Math object returns the integer value rounded to the decimal point. On the other hand, the round method of nexacroAPI allows you to specify where to round.

How to implement an example

1

Configuring Form Screen

Place the Static component, Edit component, and Button component.

2

Writing Button Component Click Event Function

Write the event function to be executed when the Button component is clicked. Verify the input value in the fn_percent function and display the verified result in the Edit component.

this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
    var nRtn = this.fn_percent(this.Edit00.value, this.Edit01.value, this.Edit03.value);
    this.Edit02.value = nRtn;
};

3

Writing fn_percent Function

If there is no rounding option (nFractionDigit), then use the round method of the Math object, and if there is the option value, use the round method of nexacroAPI.

this.fn_percent = function(nTop, nBottom , nFractionDigit)
{
    var nRtn;
	if (nBottom == 0)
    {
        nBottom = 1;
    }
	
    if (nFractionDigit == null || nFractionDigit == "" || nFractionDigit == "undefined")
    {
		nRtn = Math.round(nTop/nBottom*100);
    } else {
		nRtn = nexacro.round(nTop/nBottom*100, Number(nFractionDigit));
	}
	
    return nRtn;
}

4

Checking with QuickView

Run it with QuickView (Ctrl + F6) and enter the value to check.