|
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
|
|
|
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.
|
|
|
|
|
|
|
|