Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 26th, 2004, 12:10 PM
shazbot9 shazbot9 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 shazbot9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Trying to remove a decimal from a number

I am trying to remove the decimal from a number before I update a database. The strImplied is equal to 157.92 before the below line of code is executed. After the line of code is executed, the strImplied is equal to 15791. I need it to be 15792. Can anyone help out on this problem. Thanks.

strImplied = str(int(float(strAmount) * 100))

Reply With Quote
  #2  
Old May 26th, 2004, 12:26 PM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Code:
int(round(float('157.92')*100))

This is of course because there's no exact binary representation of 157.92. float('157.92') is in fact less than 157.92. This means that int() for your value will truncate it, giving you 15791.

Last edited by percivall : May 26th, 2004 at 12:30 PM.

Reply With Quote
  #3  
Old May 26th, 2004, 01:20 PM
shazbot9 shazbot9 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 shazbot9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It Works great

Thanks for your help. It works great.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Trying to remove a decimal from a number


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT