I have a value of exactly 1.08:43:23
in my textbox, which is equal to 1d, 08:43:23. I wanted to convert the value to decimal for me to multiply it by another decimal value, however when I used Convert.ToDecimal
it returns the error
Input string is not a valid format
Is Convert.ToDecimal
not appropriate for this kind of conversion ? Is there a way to create a decimal value from such input?
Is
Convert.ToDecimal
is not appropriate for this kind of conversion ?
No. You need to parse it to TimeSpan
first (with a culture that has :
as a TimeSeparator
of course.). Then you can get which duration type do you want as a double
from it.
var ts = TimeSpan.Parse("1.08:43:23", CultureInfo.InvariantCulture);
Then you can use TotalXXX
properties which type duration do you want as a double
(seconds, milliseconds etc.).
This will give u total number of ticks ..
decimal dec = Convert.ToDecimal(TimeSpan.Parse("11:30").Ticks);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With