[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: How do I round off a float to x decimal places

Cameron, Gemma (UK)

10/16/2006 7:50:00 AM


Might be a little late but here's my method

# round only works on integers so have to
# multiply the float to by 10000 to round it to 2 decimal places
# and then correct the position of the decimal by
# dividing by 100.0

def round(float, num_of_decimal_places)
exponent = num_of_decimal_places + 2
@float = float*(10**exponent)
@float = @float.round
@float = @float / (10.0**exponent)
end


Gem

-----Original Message-----
From: Jatinder Singh [mailto:jatinder.saundh@gmail.com]
Sent: 13 October 2006 17:13
To: ruby-talk ML
Subject: Re: How do I round off a float to x decimal places

*** WARNING ***

This mail has originated outside your organization, either from an
external partner or the Global Internet.
Keep this in mind if you answer this message.


********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************