JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 16th, 2007, 09:02 PM
phpscripter phpscripter is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 phpscripter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 53 m 38 sec
Reputation Power: 0
Math.ceil depending on the number of decimal places

Hi,
I've got an issue and I hope you can help me to get this going.
Well, to start with, we all know what ceil does:

ceil(x) - Rounds up the value of "a" to the next integer. If the value is a already whole number, the return value will be the same as the passed value.
Code:

The example returns 13. resultval = Math.ceil(12.01)

------------------
The issue:

In particular this is about a tax rate of 12.5% whereas totaldue_ is the total of a given shopping basket and ship_cost_ is a given figure, say 7.91:

Code:
tax_t = totaldue_*0.125; tax_s = ship_cost_*0.125;


Now, if I for example would need to only ceil decimal places (2) I'd do something like that.

Code:
tax = ((Math.ceil(tax_t*100))/100)+((Math.ceil(tax_s*100))/100);


That gives me the ceiled total
totaldue_ = totaldue_+ship_cost_+tax;

So far everything is fine and everything works as expected as long as the sum of tax_t = totaldue_*0.125; and/or tax_s = ship_cost_*0.125; has more that 2 decimal places, for example:

Code:
tax_t = 160.81*0.125 this totals = 20.10125
tax_s = 7.91*0.125 this totals = 0.98875


The following causes the problem for me:

Code:
tax_t = 160.80*0.125 this totals = 20.1 
tax_s = 7.91*0.125 this totals = 0.98875


Can you see the difference?

In the event that I get a number with less than 3 decimal places I don't want to ceil. Only in that particular case I rather need to floor or do nothing.

So I guess I'd need something to determine the number of decimal places against the result of that math. How could I realise that?

Cheers
Jan

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Math.ceil depending on the number of decimal places


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