This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes convert Postiive number to negative.. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "convert Postiive number to negative.. " Watch "convert Postiive number to negative.. " New topic
Author

convert Postiive number to negative..

varun bihani
Ranch Hand

Joined: Aug 11, 2003
Posts: 96
Is there any prebuilt function in java that convert positive number to negative number ??
eg, abs() convert negative to positive.. .


<a href="http://www.galaxyweblinks.com" target="_blank" rel="nofollow">www.galaxyweblinks.com</a><br /><a href="http://www.freechatcode.com" target="_blank" rel="nofollow">www.freechatcode.com</a><br /><a href="http://www.onlinefamilytreemaker.com" target="_blank" rel="nofollow">www.onlinefamilytreemaker.com</a>
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547



something like that ? (and you can write it even shorter ...)

pascal
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Unary operator -


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
int pos = 10;
int neg = -pos;
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if you want to guarantee a negative number

Math.abs(number) * -1
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1295
Originally posted by Michael Dunn:
if you want to guarantee a negative number

Math.abs(number) * -1


Another smart (and handsome) rancher also suggested this here


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: convert Postiive number to negative..
 
Similar Threads
Byte
Two's complement question
method to convert positive number to negative
Trying to understand shifting in Java.
Converting Hex to decimal - with a twist