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
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β¦
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.