Skip to content

Instantly share code, notes, and snippets.

@mithublue
Created November 1, 2016 06:10
Show Gist options
  • Save mithublue/56245d599efb6630c1aa0e5fe67ef4db to your computer and use it in GitHub Desktop.
Save mithublue/56245d599efb6630c1aa0e5fe67ef4db to your computer and use it in GitHub Desktop.
Precision of mathamatical operation of data of double data type
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