Adding discount script...

This is a discussion on Adding discount script... within the PHP Language forums, part of the PHP Programming Forums category; All, I have been working on a small script that will detect the day of the month, and apply that ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-04-2004
StinkFinger
 
Posts: n/a
Default Adding discount script...

All,
I have been working on a small script that will detect the day of the month,
and apply that percent off of an item. For example, on the 3rd, 3% off,
12th, 12% off, etc.

This is what I have so far, does it look correct ?

$t = (intval(date("j")) / 10);
$p = explode(".", $price); // $price is returned from the db in this format
10.00
$np = number_format($p[0] - $t, 2);

Any improvements ?
Thanks.


Reply With Quote
  #2 (permalink)  
Old 09-04-2004
Alvaro G. Vicario
 
Posts: n/a
Default Re: Adding discount script...

*** StinkFinger escribió/wrote (Sat, 4 Sep 2004 12:52:20 -0800):
> $p = explode(".", $price); // $price is returned from the db in this format
> 10.00


If you want to truncate the price just use (int)$price in your formula. I
just wonder why you don't round().

--
--
-+ Álvaro G. Vicario - Burgos, Spain - ICQ 46788716
+- http://www.demogracia.com (la web de humor para mayores de 100 años)
++ «Sonríe, que te vamos a hacer una foto para la esquela»
--
Reply With Quote
  #3 (permalink)  
Old 09-05-2004
StinkFinger
 
Posts: n/a
Default Re: Adding discount script...

Thanks. I've reworked the code and came up w/this:

//$p is returned from a db like this 10.00
$np = number_format((intval($p) - (intval(date("j")) / 10)), 2);
echo $np; //returns 9.60 (for today)

I cannot figure out either how or why I would use round().
Can you provide an example ?
Thanks.

"Alvaro G. Vicario" <kAlvaroNOSPAMTHANKS@terra.es> wrote in message
news:ajh7z5rzrc7h$.v0nn7qif0pk0$.dlg@40tude.net...
> *** StinkFinger escribió/wrote (Sat, 4 Sep 2004 12:52:20 -0800):
>> $p = explode(".", $price); // $price is returned from the db in this
>> format
>> 10.00

>
> If you want to truncate the price just use (int)$price in your formula. I
> just wonder why you don't round().
>
> --
> --
> -+ Álvaro G. Vicario - Burgos, Spain - ICQ 46788716
> +- http://www.demogracia.com (la web de humor para mayores de 100 años)
> ++ «Sonríe, que te vamos a hacer una foto para la esquela»
> --



Reply With Quote
  #4 (permalink)  
Old 09-05-2004
Alvaro G. Vicario
 
Posts: n/a
Default Re: Adding discount script...

*** StinkFinger escribió/wrote (Sat, 4 Sep 2004 15:02:21 -0800):
> I cannot figure out either how or why I would use round().
> Can you provide an example ?


If the price is 25.99 and you truncate 25, you carry an error of 99 cents.
If you round to 26, the error is 1 cent. Rounding, the error is never
larger than 50 cents.


--
--
-+ Álvaro G. Vicario - Burgos, Spain - ICQ 46788716
+- http://www.demogracia.com (la web de humor para mayores de 100 años)
++ «Sonríe, que te vamos a hacer una foto para la esquela»
--
Reply With Quote
  #5 (permalink)  
Old 09-05-2004
StinkFinger
 
Posts: n/a
Default Re: Adding discount script...

> If the price is 25.99 and you truncate 25, you carry an error of 99 cents.
> If you round to 26, the error is 1 cent. Rounding, the error is never
> larger than 50 cents.


Ok, I see now. Thanks for pointing that out. In my case, all my prices are
even dollar amounts, but I will keep that in mind if I ever need to change
it.

Thanks again.


Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:09 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0