Data type of expansion
Processing banking
Speaking of numbers, we may first think of int, float data types
But for "money", the use of floating-point data type is not enough, Int is not
Why not float?
- Because the float double float is limited, discrete, rounding errors, approximately, close but not equal
- When we deal with these data require precision floating-point numbers should be avoided
float f=0.1f; //0.1
double d=1.0/10; //0.1
System.out.println(f==d); //false
float d1=2212121454554f;
float d2=d1+1;
System.out.println(d1==d2) //true
Visible when using the float it is inaccurate to compare
So, what data should be processed banking?
Using mathematical tools java BigDecimal
Type Conversion
int i=128;
byte b=(int)i; //由高到低 强制转换
double b=i; //由低到高 自动转换