Don't use int(), use round().  int() truncates, and is equivalent to
the floor() (the inverse of ceiling()) function found in most
languages.  round(), on the other hand, follows normal rounding rules
(0-4 goes down, 5-9 goes up).

cheers,
barneyb

On 12/12/05, Shawn McKee <[EMAIL PROTECTED]> wrote:
> So if I need to accurately convert a floating point number with X digits in 
> the decimal portion to one with Y (Y < X) digits what do I do?  For instance 
> 10.3456 to 10.34.
>
> I have to do currency conversion prior to hitting a credit card.  The credit 
> card is limited to two decimal points but the conversion can end up with many 
> more.  I wrote this:
>
> numOut = (int(numIn * 100))/100
>
> and thought all would be well. However it is regularly off by .01 which is 
> obviously a problem when dealing with money.
>
> Shawn McKee
>

--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 100 invites.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:226883
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to