Reputation:
I'm importing data from MS SQL Server with Java and JDBC. The data in my database have 2 fractional digits.
Upvotes: 0
Views: 68
Reputation: 27
Completely agree with the explanation from Tom H. If you want to format data on the user side you can use DecimalFormat or to be more precise as it is currency try using NumberFormat's currency instance.
DecimalFormat df = new DecimalFormat("##.00");
String result = df.format(Double.parseDouble((data)));
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
String result = nf.format(new BigDecimal(data));
You should change the Locale according to your requirement. FYI, using currency instance will return value with corresponding currency sign from Locale.
Upvotes: 0
Reputation: 47464
The MONEY
datatype in SQL Server has four digits of precision, so what you're seeing is what should be expected. You can use DECIMAL
if you only want two digits of precision.
Your front end should be able to display the data however it wants to display it though.
Upvotes: 2