
You'd still use the Pow mechanism but instead of dividing you would multiply.

You could also do the opposite if someone stated they wanted to take a decimal like 19.56 and convert it to an int. Return x/(decimal)Math.Pow(10.00, powBy) Ĭall it like so: decimal d = IntToDec(1956, 3) With that being said, wrap it into a function: decimal IntToDec(int x, int powBy)

Given an input (number of decimal places) make the conversion based on that.ĭecimal d = x/(decimal)Math.Pow(10.00, powBy) So the pattern signifies we are dealing with a power of 10 ( Math.Pow(10, x)).

Notice the pattern yet? As we increase the digits to the right of the decimal place we also increase the initial value being divided (10 for 1 digit after the decimal place, 100 for 2 digits after the decimal place, etc.) by ten times that. Since you are trying to make the number smaller couldn't you just divide by 10 (1 decimal place), 100 (2 decimal places), 1000 (3 decimal places), etc.
