Issue
I would like to be able to limit the amount of decimal places that are shown from a print function without any sort of rounding system
v = 8.836333333333339
print ('%.2f' % v)
This code will print the value of v to two decimal places but also rounds it up or down, how could I make it stop this rounding please?
Solution
You could process it as a string:
v = 8.836333333333339
s = str(v)
print s[:s.find('.')+3]
# prints 8.83
Answered By - ooga Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.