开发者

how to get certain precision values in java?

I am passing some values to database(SQ开发者_运维技巧L Server) here one of the field contains money type data filed.. while i am passing values for eg:25.21 , in database it was storing 25,2100 Here my question was, i have to show the value in page like 25.21 (only two values after decimalpoint)i have to remove precision values after two decimal. can u send code for that?

Note in java pojo i am using BigDecimal to that property


If it is a numeric field in the database, it is not storing it as 21,2500. Instead - it is storing it as 21.25, but the interface that you are using is formatting it for you. In this case it is showing you 4 digits after the decimal and putting a , in for the decimal separator. I suggest that you do just what your database interface is doing, format the data the way you need it.

See the JavaDoc for DecimalFormat and the Java tutorial on custom formats for some details.


I suggest you try either DecimalFormat, or String.format or PrintStream.printf depending on what is most appropriate for you. I also suggest you try to accept more answers. ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜