Reset double variable

Hi All,

I have an “double” variable that value is an empty but its showing zero.
i want that if the value is null so, its should be null not zero.
So, kindly suggest how i can reset the value.

Regards,
Meenakshi

Hello,
double is a primitive type, it cannot be null though.

1 Like

@Meenakshi6246,

Double will always give you the value of “0” and we can’t assign null value to double or system.DBNull to double.

You can do onething,

If double.tostring = “0”, then you can do the required

then, how we can reset the double variable.

Hi @Meenakshi6246

I would use a string type variable to handle these scenarios. I would initialize the string to null. Then in the process values can be assigned without a problem to a string. However when I want to perform calculations on the numeric values I would then do a convertion to double format using
Double.Parse(StringVariable).

This will also allow you to initialize it to null when you don’t want to use a default zero in it.

I know, there is a extra level of processing to get it converted to double when required. But this is the best way that I would recommend. I’m also following the same way of doing it.

My answer is also backed by…

To reset it and check condition: Assign it to the zero, or any other number that you think is impossible to achieve in the process.

Regards

Use this and no need to reset there, you can directly pass the required value if it gives the value as 0

1 Like

then, how i convert the double value into in string.
because when I used .Tostring ,its showing me an error.

2 Likes

use Convert.ToString(DoubleVariable)

why because if double variable is null or zero it will handle it however .ToString cannot handle null.

Cheers!! @Meenakshi6246

1 Like

agree with @HareeshMR

2 Likes