Wrox Programmer Forums negative number returned when subtracting
 |
 Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
 Welcome to the p2p.wrox.com Forums. You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

November 29th, 2005, 06:04 AM
 gavmc Registered User Join Date: Nov 2005 Posts: 7 Thanks: 0 Thanked 0 Times in 0 Posts
negative number returned when subtracting

Hello wondering if anyone can help me.

I am performing a calulcation on two numbers (a - b) that are not always the same and i get returned a negative number which is incorrect.

For example if a = 10, and b = 7 then 10 - 7 = 3, but if a = 7, and b = 10 then 7 - 10 = -3.

i am just wondering how in asp code i can fix it so that the result would always be 3 and not -3

Any help would be appreciated

G.

November 29th, 2005, 06:16 AM
 ChrisScott Friend of Wrox Join Date: Jul 2003 Posts: 683 Thanks: 0 Thanked 1 Time in 1 Post

You can use Abs() to do this...
Code:
`myNum = Abs(a - b)`
HTH,

Chris

November 29th, 2005, 06:34 AM
 gavmc Registered User Join Date: Nov 2005 Posts: 7 Thanks: 0 Thanked 0 Times in 0 Posts

Thanks alot, will try to use abs. Was just starting to write if a > b then make highNumber else make lowNumber etc..

Abs will save me alot of time as have many calculations to perform

G.

 Similar Threads Thread Thread Starter Forum Replies Last Post Making a number negative Corey Access 1 February 2nd, 2007 11:48 AM Subtracting Quantities rsm42 ASP.NET 1.0 and 1.1 Basics 2 January 7th, 2007 10:44 AM Dynamic number of columns returned from sp dreadjr BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 1 July 5th, 2006 03:42 PM Subtracting a value from a previous value Wes Access 8 March 29th, 2006 12:17 PM SUM operator returns a negative number cdias XSLT 7 December 31st, 2004 05:08 PM