473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

negative int to positive int value

Does anyone know if there is a easy way to change a negitive int value into a
positive int value.

int a = -105 > change this to 105.

With other words is there a command to change to neg sign into pos sign ?

Bardo Versteeg
Nov 17 '05 #1
4 50335
(int)Math(Abs(<value>));

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"bardo" <ba***@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
Does anyone know if there is a easy way to change a negitive int value
into a
positive int value.

int a = -105 > change this to 105.

With other words is there a command to change to neg sign into pos sign ?

Bardo Versteeg

Nov 17 '05 #2
If you mean to change it after a value has already been assigned to 'a':

Negative or Positive --> Positive
a = Math.Abs(a)

Reverse the sign
a = -(a)
or
a = a * -1
"bardo" <ba***@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
Does anyone know if there is a easy way to change a negitive int value
into a
positive int value.

int a = -105 > change this to 105.

With other words is there a command to change to neg sign into pos sign ?

Bardo Versteeg

Nov 17 '05 #3
bardo wrote:
Does anyone know if there is a easy way to change a negitive int value into a
positive int value.

int a = -105 > change this to 105.

With other words is there a command to change to neg sign into pos sign ?


a = a<0 ? -a : a; // if a is negative >>or<< positive

Till
Nov 17 '05 #4
Thanks Bob , Stephany and Till,

Math.abs(<value>) does the trick.
Also thanks for the other tips. a = -(a) is a handy one to remember.

Bardo

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tripp Knightly | last post by:
I have a lookup table from which I want to categorize various bands of customer net income. Some of the income is positive, some is negative. The bands vary in size (ie, <500, -200 to 0, 100 to...
5
by: Peter Bailey | last post by:
I have an expression that returns the week number in a row but descending from a date: Week Number: DateDiff("ww",DateAdd("ww",1,forms!FrmBookingCurveInput!TxtStart.value),) It allows me to...
29
by: Peter Ammon | last post by:
What's the most negative double value I can get? Is it always guaranteed to be -DBL_MAX? If so, why (or rather, where)? Thanks.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.