Reputation: 1461
I need a way to multiple the a float by the number of decimal places.
e.g.
Number = 10.04
Number of Decimal Places = 2
Result = 1004
Number = 123.421
Number of Decimal Places = 3
Result = 123421
so on and so forth, I have a method written to return the number of decimal places, but how can I expected result as mentioned above?
Upvotes: 0
Views: 348
Reputation: 346566
A float
value does not have decimal places. So if you want to do anything that involves decimal places, you have to stop using float
. Otherwise, you'll inevitably get unexpected (wrong) results.
Read the Floating-Point Guide for details.
Upvotes: 3
Reputation: 132
Are you just moving the decimal point? If so... #EDITTED# result = number * (10 to the power of decimal places)
Upvotes: 1
Reputation: 1461
Got another way:
Float.toString(10.234f).replace(".", "")
returns 10234!!
Upvotes: 0