Solved

How do I multiply negative number with Perl?

Posted on 2003-11-23
3
963 Views
Last Modified: 2013-12-25
I need to multiply a variable that contains a negative value by negative one.  Such as $test=(-1*$amount) where amount is negative.  I can't even get print "Test (-1*$amount)"; to work.  This prints: -1*-300.  
0
Comment
Question by:Shearer-Services
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 25 total points
ID: 9807635

Either do

$test = -1 * $amount;
print "$test\n";

or

print -1 * $amount , "\n':

0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 25 total points
ID: 9808762
 $test=(-1*$amount) ;
should work.
so would
  $test = -$amount;

  print "Test (-1*$amount)";
will just print the "Test (-1*" litterally
perhaps you meant
  print "Test", -1*$amount,"\n";
0
 

Author Comment

by:Shearer-Services
ID: 9810319
Despite my typo, you both helped answer the question.  Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question