Copy sign

ReturnMethodSummary
static doublecopySign(double magnitude, double s)Returns the first floating-point argument with the sign of s.
static floatcopySign(float magnitude, float s)Returns the first floating-point argument with the sign of s.

public class Main {
  public static void main(String[] args) {

    System.out.println(Math.copySign(2.2,3.3));
    System.out.println(Math.copySign(2.2,-3.3));
  }
}

The output:


2.2
-2.2
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.