始终返回正值 [英] Always return positive value
本文介绍了始终返回正值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数字,它可以是负数或正数,但我只想返回正值.
I have a number it could be negative or positive but I simply want to return the positive value.
-4 -> 4
5 -> 5
我知道我可以做一个简单的if检查,看看它是否为零然后返回它*-1
,但是我不记得我一生中真正的Maths
运算符是什么!
I know I can do a simple if check, see if its zero then return it *-1
but I can't remember for the life of me what the actual Maths
operator is!
谁能告诉我这是什么吗?
Can anyone tell me what it is?
推荐答案
按
Use System.Math.Abs
as documented here.
这篇关于始终返回正值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文