codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Math.ceil depending on the number of decimal places  phpscripter at 00:18 on Tuesday, April 17, 2007
 

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.

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:


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.


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:

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:

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

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

  Re: Math.ceil depending on the number of decimal places  amery buck at 14:49 on Monday, March 22, 2010
 

Beautiful blog with great informational content. Mostly certifications related and decimal places related topics are really very good. testking 642-892, testking 642-971 and testking 642-972 are also good topics. Thanks for this great sharing.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: PHP Shopping Basket
•  How we can view a Word document in a PHP page?
•  New to this forum
•  Shunjie Hu Speaks on Real-time web with Adobe Flex 4 & Flash Player 10.1 at AFPS 2010
•  CSS 3.0 animation features
•  Re: JavaScript: Not working in Firefox 3.x
•  Re: How to know the Control Type in javascript
•  Re: $_GET not working
•  Downloading a file using http


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010