0

This is my issue.

Math.Truncate(-18141235.58 * 100.0) / 100.0
o/p: -18141235.57

.01 difference is coming. I have tried solutions as on (Truncate Decimal number not Round Off) but doesnt work.

Issues resolves if I use 1000, but I want it to return 2 decimal places only, which might not be input value all time.

Math.Truncate(-18141235.58 * 1000.0) / 1000.0
Community
  • 1
  • 1
Shreyash
  • 13
  • 5
  • 1
    Those are doubles, not decimals – James Sep 08 '15 at 15:49
  • 5
    Welcome to the exciting world of floating point! Floating point numbers are not exact. There will be issues like this. Try using the `decimal` datatype by adding the `m` suffix to your constants, e.g.: `Math.Truncate(-18141235.58m * 100.0m) / 100.0m` and see if that helps. – dmeglio Sep 08 '15 at 15:49

0 Answers0