English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Let's say you have a number like 12. Would it be true to say there's a zero in the hundreds place? If so, is there a calculation I could perform on the number 12 that would yield 0? What if I had a more complicated number like 121.0021, is there a calculation I could perform on this number that would yield 2 if I wanted to know the digit in the tens place or thousandths place?

2006-10-10 17:53:20 · 2 answers · asked by Kanayo 2 in Science & Mathematics Mathematics

2 answers

To get the kth digit:

[ floor(x / 10^(k-1)) ] mod 10

where floor(x) is the greatest integer less than or equal to x
and a mod b is the remainder when a is divided by b

2006-10-10 18:13:57 · answer #1 · answered by James L 5 · 0 0

I don't think this is what you want, but in a computer we use the Integer function to get the integer portion of a number. This could be used with the 12 as "Integer( 12 / 100)" which would return 0. Similarly in the 10/1000th place you would take

Integer((x * 10 - Integer( x * 10) ) * 10)

This gives the fractional part and then the Integer part.

2006-10-10 17:59:55 · answer #2 · answered by rscanner 6 · 0 0

fedest.com, questions and answers