Jared
Jared

Reputation: 2483

Compute the hundreds digit of an arbitrary real number

How would I convert this number (42519.36) to a whole real number (5)?

42519.36 = 5

What is the most efficient way in C#?

Thanks!

Upvotes: 3

Views: 4078

Answers (2)

CodesInChaos
CodesInChaos

Reputation: 108830

Use the remainder operator:

int hundredDigit=(int)Math.Abs(number/100%10)

Upvotes: 14

mbeckish
mbeckish

Reputation: 10579

Here you go:

(x % 1000 - x % 100) / 100

Upvotes: 2

Related Questions