How to put floating/Double value in Timespan?

Recommended Answers

All 6 Replies

well using

TimeSpan ts = new TimeSpan()

it only accepts ints, so you are going to have to convert your floats/doubles to ints

hi..

Time span can access seconds, milliseconds, mins, hours....float value has to be converted into int format..

TimeSpan ts = new TimeSpan(0,0,(int)(2))

How to convert this int value to float?

float x = 12.4f;
int z = (int)x;

//result
//z == 12

or exactly as you have done

I want floating value in timespan! i.e with decimal point

The TotalDays, TotalHours, TotalMinutes, TotalSecond, TotalMilliseconds are all doubles that can be displayed as floating point numbers.

using System;

namespace DW_405765_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         TimeSpan ts = new TimeSpan(1, 1, 1, 1);
         Console.WriteLine(ts.TotalMilliseconds.ToString("F02"));
      }
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.