 # Get the absolute value of a decimal number

Hey Uipath world,

I have a decimal number (-0.25) and I wanna get the absolute value of it.
if I use Math.abs(-0.25), I will certainly get 0 as result.
My goal is to have :
input : -0.25
output : 0.25

How can we get the absolute value of decimal number?
Thank you.

@WilliamC

Try this.

``        output = input.Tostring.Replace("-","")``

Hi @WilliamC,

Assign value in double type
Double val= Math.abs(-0.25)
Or
“-0.25”.Replace("-","")

@WilliamC
String actions on Numbers ist sometimes risky due of sideeffects. In your Case you can Check If number < 0 and Then multiply with -1. The Rest will Go as mentioned above

I dont know why you are saying this but you are not right on that statement… Math.Abs(Convert.ToDecimal("-0.25")) will certainly return a decimal of 0.25…

1 Like

This is a really bad idea because the string representation of a decimal number may not be equal to the value that is stored, especially depending on how many decimal places are being stored.