Always return positive value

前端 未结 7 1436
清酒与你
清酒与你 2020-12-11 14:15

I have a number it could be negative or positive but I simply want to return the positive value.

-4 -> 4
5 -> 5

I know I can do a sim

相关标签:
7条回答
  • 2020-12-11 14:59

    You're looking for Math.Abs.

    0 讨论(0)
  • 2020-12-11 15:00

    Use System.Math.Abs as documented here.

    0 讨论(0)
  • 2020-12-11 15:00

    If you're working with floats in Unity, use Mathf.Abs

    0 讨论(0)
  • 2020-12-11 15:04

    You can use Math.Abs like public static int Abs (int value);

    0 讨论(0)
  • 2020-12-11 15:12

    There is an overloaded method Math.Abs can be used in your case. It can take Double, Int16, Int32, Int64, SByte, Single or Decimal as an argument.

    0 讨论(0)
  • 2020-12-11 15:16

    Use this :

    int PositiveNo = System.Math.Abs(NegativeNoHere);
    
    0 讨论(0)
提交回复
热议问题