For the amount of storage, through the review and the actual project in the use, roughly is two kinds of data types.
One is to use long, storage units as points, or smaller units, and then display or calculate the time to do a unified conversion.
The second is to use double, the time of the operation of the conversion, conversion to BigDecimal for the operation, I used in the project is the second, this method requires the operation of the double type of the appropriate
To achieve the exact purpose of the calculation.
So, I expanded a tool class (on-line resources to not reinvent the wheel):
PackageCom.test.bigDecimal;ImportJava.math.BigDecimal;/*** Because Java's simple type does not accurately operate on floating-point numbers, this tool class provides fine-grained floating-point arithmetic, including subtraction and rounding. */ Public classarith{//Default division operation Precision Private Static Final intDef_div_scale = 10; //This class cannot be instantiated PrivateArith () {}/*** provides accurate addition operations. * @paramv1 summand *@paramV2 Addend *@returntwo parameters of A and*/ Public Static DoubleAddDoubleV1,Doublev2) {BigDecimal B1=NewBigDecimal (double.tostring (v1)); BigDecimal B2=NewBigDecimal (Double.tostring (v2)); returnB1.add (B2). Doublevalue (); } /*** provides accurate subtraction operations. * @paramv1 minuend *@paramv2 *@returnthe difference of two parameters*/ Public Static DoubleSubDoubleV1,Doublev2) {BigDecimal B1=NewBigDecimal (double.tostring (v1)); BigDecimal B2=NewBigDecimal (Double.tostring (v2)); returnb1.subtract (B2). Doublevalue (); } /*** provides accurate multiplication operations. * @paramv1 by multiplier *@paramV2 Multiplier *@returnproduct of two parameters*/ Public Static DoubleMultiplyDoubleV1,Doublev2) {BigDecimal B1=NewBigDecimal (double.tostring (v1)); BigDecimal B2=NewBigDecimal (Double.tostring (v2)); returnb1.multiply (B2). Doublevalue (); } /*** Provide (relative) accurate division operations, when there are no more than an endless situation, accurate to * after the decimal 10 digits, after the number rounded. * @paramV1 Dividend *@paramv2 Divisor *@returntwo parameters of the quotient*/ Public Static DoubleDivDoubleV1,Doublev2) { returnDiv (V1,v2,def_div_scale); } /*** Provide (relative) accurate division operations. When the exception occurs, the scale parameter refers to the fixed precision, and the subsequent numbers are rounded. * @paramV1 Dividend *@paramv2 Divisor *@paramthe scale representation needs to be accurate to several points after the decimal point. * @returntwo parameters of the quotient*/ Public Static DoubleDivDoubleV1,DoubleV2,intScale ) { if(scale<0){ Throw NewIllegalArgumentException ("The scale must is a positive integer or zero"); } BigDecimal B1=NewBigDecimal (double.tostring (v1)); BigDecimal B2=NewBigDecimal (Double.tostring (v2)); returnb1.divide (b2,scale,bigdecimal.round_half_up). Doublevalue (); } /*** Provides precise rounding of decimal digits. * @paramv need to round the number *@paramA few * after the decimal point@returnresults after rounding*/ Public Static DoubleRoundDoubleVintScale ) { if(scale<0){ Throw NewIllegalArgumentException ("The scale must is a positive integer or zero"); } BigDecimal b=NewBigDecimal (double.tostring (v)); BigDecimal One=NewBigDecimal ("1"); returnb.divide (one,scale,bigdecimal.round_half_up). Doublevalue (); } }
Using the above tool method, the data is calculated and accurate.
About the amount of data stored in e-commerce development