Reputation: 25
Didn't able to find getFloat
method for float data type. Whereas it shows some default method like getString()
, getInt()
, getDouble()
. But my issue is I want to get this into float.
I tried using getInt
but it gives rounded number not floating point
trade.client_sgxbfmtm = String.valueOf(singleRow.getInt("client_sgxbfmtm"));
Upvotes: 0
Views: 349
Reputation: 16184
Update: if this is financial information then you likely don't want to use IEE754 floating point values. These are binary formats, so can't represent values like 0.1
accurately. Given that you seem to be wanting to convert back to string, I'd assume that you might be able to do something like:
trade.client_sgxbfmtm = singleRow.getString("client_sgxbfmtm");
and so not introduce any inaccuracy by converting to an IEEE float and back again. This way your code doesn't know or care that the value contained in the string might be numeric. If you're actually doing something with the number, then the comments suggesting the use of BigDecimal
might be better. But if you're just converting back to String
then there's no point in going via anything.
A double
follows the same standard as a float
, just to a higher precision. Hence using getDouble
and then casting to a float
is likely what you want to be doing.
Moreover, most contemporary CPUs are able to work with (64bit) double
s at the same speed as (32bit) float
s. The only practical difference comes when you're dealing with large, densely packed arrays of them (i.e. thousands or millions of items) where the space savings make sense, or you're using specialised maths libraries that make use of vectorised operations.
Upvotes: 2