Question

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?

Was it helpful?

Solution

Are you just moving the decimal point? If so... #EDITTED# result = number * (10 to the power of decimal places)

OTHER TIPS

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.

Got another way:

Float.toString(10.234f).replace(".", "")

returns 10234!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top