始终返回正值 [英] Always return positive value

查看:80
本文介绍了始终返回正值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数字,它可以是负数或正数,但我只想返回正值.

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?

推荐答案

System.Math.Abs. abs"rel =" noreferrer>此处.

Use System.Math.Abs as documented here.

这篇关于始终返回正值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆