2

I have some variable length decimal numbers for ex: 1.123, 1.1234, 12.12345,

I need only the first 4 decimals. I can't use Math.Round() because I do not want rounded numbers, I just want to trim it and keep only first 4, like 1.1234, or 22.1234. Is there a way to accomplish this? Thank you.

Diana M00nshine
  • 115
  • 1
  • 8

2 Answers2

3

Multiply by 10000, store as integer to get rid off any remaining decimals. Divide by 10000.

spiderko_2
  • 118
  • 4
1
var result = number.ToString("n4");

check Standard numeric format strings

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99