How to convert timespan to decimal?

I have a value that is exactly equal 1.08:43:23in my text box, which is 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 it Convert.ToDecimal, it returns an error that is equal to

The input string is not a valid format

Is it Convert.ToDecimalunsuitable for such a conversion? Is there any other way to create such a value before decimal?

+4
source share
2 answers

Is it suitable Convert.ToDecimalfor such a conversion?

. TimeSpan ( , : TimeSeparator, .). , , double.

var ts = TimeSpan.Parse("1.08:43:23", CultureInfo.InvariantCulture);

enter image description here

TotalXXX , double (, ..).

+11

.

decimal dec = Convert.ToDecimal(TimeSpan.Parse("11:30").Ticks);
+2

Source: https://habr.com/ru/post/1612886/


All Articles