How to divide in the .pl file itself

Get help with nopcart Perl, PHP or ASP checkout related issues.

Moderators: Koibito, Stefko, Randy

How to divide in the .pl file itself

Postby harry2cool » Thu Oct 13, 2005 8:10 pm

Hi,
Looks simple but I could not get it after tryin for an hour or so.

I want a certain value from my shopping cart to be divided by the .pl script so that the result is emailed to me.

Example:
The value of currency is passed on to me from the checkout.
I want to divide this currency by 22 and email it to the buyer.
I want this to be done by the checkout.pl page where the email format is written.

Your total in US$ is : $total
Your total in XX currency is : $total / 22

Can anybody help please.

Rgds

Harry
harry2cool
 
Posts: 17
Joined: Thu Sep 12, 2002 5:49 pm
Location: bombay, india

Postby Stefko » Fri Oct 14, 2005 12:31 am

$c = $x / $z;


Using division will produce remainders. That is the left over amount after the "whole number". If you divide 25 by 7 the whole number is 3 and the remainder is 4. 3*7=21+4=25. Perl has a built in function to find the remainder. It uses the % symbol.

$dividend = 25;
$divisor = 7;
$remainder = $dividend % $divisor;

Operator Functionality Example
$var contains

= Assignment
$var = 8;
8

+ Addition
$var = 8 + 3;
11

- Subtraction
$var = 8 - 3;
5

* Multiplication
$var = 8 * 3;
24

/ Fractional Division
(5/2 is 2.50, not 2)
$var = 8 / 3;
2.66666666666667

% Modulus
$var = 8 % 3
2

Whole number division
$var = (8-(8%3))/3
2
KFL Technologies
Web-Enabled Solutions
e-Commerence Solutions
Stefko
Contributor / Guru
 
Posts: 833
Joined: Wed Sep 18, 2002 1:11 am
Location: Wichita, KS

Postby harry2cool » Fri Oct 14, 2005 3:12 am

Great, Thanks a ton.

I want the end result to be in maximum 2 decimals, but the result is being printed like, 2.2154

How do I do it?????
harry2cool
 
Posts: 17
Joined: Thu Sep 12, 2002 5:49 pm
Location: bombay, india

Postby Stefko » Fri Oct 14, 2005 6:19 am

Code: Select all
$amount = "19.98754";
$amount = printf("%.2f", $amount);


Returns 19.99
KFL Technologies
Web-Enabled Solutions
e-Commerence Solutions
Stefko
Contributor / Guru
 
Posts: 833
Joined: Wed Sep 18, 2002 1:11 am
Location: Wichita, KS

Postby harry2cool » Tue Oct 25, 2005 4:37 pm

Cool....... Works Great, Thanks...... :D
harry2cool
 
Posts: 17
Joined: Thu Sep 12, 2002 5:49 pm
Location: bombay, india


Return to Help: Perl/PHP/ASP Checkout

Who is online

Users browsing this forum: No registered users and 1 guest

cron