如何将时间跨度转换为小数?
How to convert timespan to decimal?
我的文本框中有一个值 1.08:43:23
,等于 1d,08:43:23。我想将该值转换为小数以便我将其乘以另一个小数值,但是当我使用 Convert.ToDecimal
时它 returns 错误
Input string is not a valid format
Convert.ToDecimal
不适合这种转换吗?有没有办法从这样的输入中创建一个十进制值?
这将为您提供报价总数..
decimal dec = Convert.ToDecimal(TimeSpan.Parse("11:30").Ticks);
Is Convert.ToDecimal
is not appropriate for this kind of conversion ?
没有。您需要先将其解析为 TimeSpan
(当然,使用具有 :
作为 TimeSeparator
的文化)。然后你可以从中得到你想要的持续时间类型 double
。
var ts = TimeSpan.Parse("1.08:43:23", CultureInfo.InvariantCulture);
然后你可以使用TotalXXX
properties你想要哪种类型的持续时间作为double
(秒,毫秒等)。
我的文本框中有一个值 1.08:43:23
,等于 1d,08:43:23。我想将该值转换为小数以便我将其乘以另一个小数值,但是当我使用 Convert.ToDecimal
时它 returns 错误
Input string is not a valid format
Convert.ToDecimal
不适合这种转换吗?有没有办法从这样的输入中创建一个十进制值?
这将为您提供报价总数..
decimal dec = Convert.ToDecimal(TimeSpan.Parse("11:30").Ticks);
Is
Convert.ToDecimal
is not appropriate for this kind of conversion ?
没有。您需要先将其解析为 TimeSpan
(当然,使用具有 :
作为 TimeSeparator
的文化)。然后你可以从中得到你想要的持续时间类型 double
。
var ts = TimeSpan.Parse("1.08:43:23", CultureInfo.InvariantCulture);
然后你可以使用TotalXXX
properties你想要哪种类型的持续时间作为double
(秒,毫秒等)。