• Post Reply Bookmark Topic Watch Topic
  • New Topic

convert Postiive number to negative..  RSS feed

 
varun bihani
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any prebuilt function in java that convert positive number to negative number ??
eg, abs() convert negative to positive.. .
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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

pascal
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unary operator -
 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int pos = 10;
int neg = -pos;
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want to guarantee a negative number

Math.abs(number) * -1
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!