Reputation: 1
I am integrating a library with my c# code. There is a decimal parameter i am using from the library. Parameter return usual decimal values mostly like: 0.24756400. But sometimes it returns values in Exponential format like: 0E-8.
When i try process the parameter in my code, for example when i parse it like this:
Decimal.Parse(paymentAuth.IyziCommissionFee);)
it gives me exception
Object reference not set to an instance of an object) when the value is in Exponential format.
If i can identify the value format (number or Exponential number) i can manage it.
So how can i identify if the value is in Exponential format? Alternatively, any suggestion to manage such situation?
Upvotes: 0
Views: 364
Reputation: 3231
If you want to parse a string that could be an exponential format into a decimal you can use the overload of the Decimal.Parse
method that takes a System.Globalization.NumberStyles
parameter to do this.
var result = Decimal.Parse(
paymentAuth.IyziCommissionFee,
System.Globalization.NumberStyles.Float
);
This specifies that the incoming string is a float, which you can represent using the exponential format you're talking about.
You can read the MSDN docs about this overload and the NumberStyles
type here :
Upvotes: 1