I am doing addition of float values and storing it in database .The sum is getting calculated as 2.22开发者_如何学JAVA2222248E4 but it should be 2222222248.4
First off, 2.222222248e4
does not equal 2222222248.4
, it equals 22222.222484
. Ne4
means N x 104
which simply shifts the decimal four places to the right.
Secondly, assuming that was a typo and the two values you have are identical, this is a presentation issue, not a data issue.
The thing in the database (assuming you're storing it as a floating point value of some sort and not some weird string) doesn't care one bit about presentation, databases are for storing data. It's the way you select the value out of the database that decides how it's formatted.
This depends entirely on what you're using to get the value out (which you haven't really specified). For example, DB2 would allow you to use:
select cast (float_column as decimal (5,2))
to format the number something like 999.99
.
精彩评论