# Decimal point

Hi.

Is there a way to return a value of a specific decimal place?

what I mean is if I have the number 0.158

I want value1 to equal the first decimal place (tenths place) , value2 to equal the number in the hundreths place, and value 3 to equal the number in the thousandths place.

so it would be
value1 =1
value2 =5
value3 =8

Is this possible, or any pointers on where to start to program this functionality? Is there a way to clip off numbers or something.

I need this functionality to store extra data within 1 number. Thanks for any ideas.

value1 = value1.ToString(“f2”);

Floating point is inaccurate, you could lose your numbers if you get too far out. While I cannot understand exactly why you are trying to do this with decimals, if you are trying to pack numbers for transmission, it’s better to stick them into integers, and use “” and “>>” (and and right shift) to get the bits out.
If you just have to have floating point, then you should use multiply, divide and modulus (*, / and %) to get the individual values.

ex:

val1 = ((int)Math.Round(1000.123f * 10.0f)) %10; // get the tenths = 1
val2 = ((int)Math.Round(1000.123f * 100.0f)) %10; // get the hundredths = 2
val3 = ((int)Math.Round(1000.123f * 1000.0f)) %10; // get the hundredths = 3

But like I said, be careful, floating point is close, but not accurate, your numbers can change on you.

Thanks Jaimi!