Introducing nexacro.Decimal Object
This is the object provided to process data that is outside the stable support range of JavaScript Number type.
JavaScript can process values from -(2 to the 53rd -1) to (2 to the 53rd -1). Outside of this range, incorrect values may be displayed, and accurate values cannot be obtained during calculations. It is a value of about 9 quadrillion. It may not be used in general business, but it is a number that can occur in finance or statistics. For example, in 2018, the Korean national net worth is estimated to be about 15 quadrillion, 511 trillion, and 700 billion won (source: National Statistical Office 2018 National Balance Sheet). In the press release, it is possible to calculate since the last digits are cut off and used in a way such as "100 billion units". However, if you need to process the actual value, then you have to process a value larger than the supported range provided by JavaScript.
The nexacro.Decimal object can process up to 24 digits (999.9 sextillion).
You can use the BigInt object, which is the JavaScript built-in object, in some web browsers. Please refer to the table below for the support range of the BigInt object and the nexacro.Decimal object (as of December 2019).
Edge | Chrome | Safari | Firefox | Opera | |
---|---|---|---|---|---|
nexacro.Decimal | O | O | O | O | O |
BigInt | X | O | X | O | O |
Using BIGDECIMAL Type in Grid Component
When setting the column in the Dataset object, if the type value is set as "BIGDECIMAL" and the Dataset is bound, the set value is processed as the nexacro.Decimal object.
Example
Check how a 19-digit numeric value is processed in another type of Dataset column. You can see how the data is displayed and how the total is displayed.
When the type is INT, a completely different value is displayed, and when the type is FLOAT, it is displayed as an approximate value. Only BIGDECIMAL displays the entered value exactly and returns the desired sum value as well.
sample_nexacro_decimal_01.xfdl
Core features used in the example
- getSum
Returns the total value by specifying the column ID value.
How to implement an example
1
Place the Grid component on the screen.
2
Add the Dataset object and set the column format and data as shown below.
Add 3 columns and set each column type to INT, FLOAT, and BIGDECIMAL. For the data, specify the 19-digit numeric value as the same value.
3
Bind the Dataset object to the Grid component.
4
Run Grid Contents Editor and add Summary Row.
5
Among the cell properties of Summary Row, set the displaytype property value to "number" and the expr property value to "dataset.getSum('[Column name]')".
6
Run it with QuickView (Ctrl + F6) and check how the value is displayed according to the type of the Dataset object.
Calculating Value Greater than 10q
The nexacro.Decimal object is processed as an object, not a number. Therefore, general operation symbols cannot be used, and separate methods or properties are supported to process operations.
Example
Enter a number in the Edit component, select the operator, and click the [Calculate] button to process the operation.
If the input value or calculation result value is larger than 24 digits, then the calculation process is not performed normally.
sample_nexacro_decimal_02.xfdl
Core features used in the example
- addDecimal, subDecimal, mulDecimal, divDecimal
This is the method for the nexacro.Decimal object calculation. The operation result value is reflected in the nexacro.Decimal object that executed the method without returning the operation result value.
How to implement an example
1
Place the Edit, Radio, Button components on the screen.
2
Set add, sub, mul, and div values as the innerdataset value of the Radio component.
3
Write the onclick event function of the Button component as follows.
this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo) { var a = nexacro.Decimal(this.Edit00.value.toString()); var b = nexacro.Decimal(this.Edit01.value.toString()); switch(this.Radio00.value) { case 'add': a.addDecimal(b); break; case 'sub': a.subDecimal(b); break; case 'mul': a.mulDecimal(b); break; case 'div': a.divDecimal(b); break; default: } this.Edit02.value = a.toString(); };
When setting the Decimal object, the value must be specified in the form of the character string.
(O) var a = nexacro.Decimal(this.Edit00.value.toString()); (X) var a = nexacro.Decimal(this.Edit00.value.toNumber()); (O) var a = nexacro.Decimal("1234567890123456789"); (X) var a = nexacro.Decimal(1234567890123456789);
Even when outputting the calculated value, it must be output by converting it to the string. If it is set as the value of the Edit component, then an error does not occur since it is converted to the string during internal processing. However, it is still safe to process it by replacing it with the string.
(O) this.Edit02.value = a.toString(); (Δ) this.Edit02.value = a;
4
Run it with QuickView (Ctrl + F6) and check if the operation of the input value is processed.