<aside> <img src="notion://custom_emoji/40d4c25b-c989-454b-9fba-7ed381030c16/169efb27-efe6-8053-b0c5-007a63ca7e5a" alt="notion://custom_emoji/40d4c25b-c989-454b-9fba-7ed381030c16/169efb27-efe6-8053-b0c5-007a63ca7e5a" width="40px" />

실수형의 종류

  1. float : 4byte
  2. double : 8byte → 기본형으로 사용 </aside>

부동소수점 표현식

image.png

실수형은 왜 기본형이 double일까요?

public class FloatTest02 {

	public static void main(String[] args) {		
		float result=0;//0.0f
		for(int i=0;i<100;i++) {
			result = result + 0.1f;
		}		
		System.out.printf("%.6f",result);//10.000002		
	}
}
public class DoubleTest {

	public static void main(String[] args) {
		double result=0.0;
		for(int i=0;i<1000000;i++) {
			result = result + 0.1;
		}
		System.out.printf("%.6f", result);//10.000000
	}
}

image.png