Alex Rivera | Logout

Truncate Decimal number not Round Off

Asked 2008-12-01T03:31:54.243
38

Possible Duplicate:
c# - How do I round a decimal value to 2 decimal places (for output on a page)

I want to truncate the decimals like below

i.e.

  • 2.22939393 -> 2.229
  • 2.22977777 -> 2.229
Edit
Report

1 Answer

0

Maybe another quick solution could be:

>>> float("%.1f" % 1.00001)
1.0
>>> float("%.3f" % 1.23001)
1.23
>>> float("%.5f" % 1.23001)
1.23001
answered 2010-01-21T14:29:55.600

Your Answer