• Post Reply Bookmark Topic Watch Topic
  • New Topic

convert Postiive number to negative..  RSS feed

 
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.. .
 
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
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unary operator -
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int pos = 10;
int neg = -pos;
 
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
 
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
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!