Created
November 1, 2016 06:10
-
-
Save mithublue/56245d599efb6630c1aa0e5fe67ef4db to your computer and use it in GitHub Desktop.
Precision of mathamatical operation of data of double data type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigDecimal; | |
public class Main { | |
public static void main(String[] args){ | |
double dNum = .012 ; | |
double sumNum = dNum + dNum + dNum; | |
System.out.println("Result : " + sumNum ); | |
//convert the double to string | |
String sNum = Double.toString(dNum); | |
//pass sNum to BigDecimal | |
BigDecimal bigVal = new BigDecimal(sNum); | |
bigVal = bigVal.add(bigVal).add(bigVal); | |
//precise value | |
System.out.println("Big Decimal Value : " + bigVal); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment