Click here to Skip to main content
13,045,422 members (69,221 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi guys!
I am trying to create an array that stores 4 lap times, for example:
Double arrayName[4] = {1.40, 1.45, 1.32, 1.20};

Then I need to add all these figures together and produce a total, average, fastest etc.

My problem is, they are not calculated as time, but as floating point numbers. Is there a way I can format the time inside the array? Or even take the total figure (as a double) and convert it to a time format in minutes/seconds?

Please keep any help you can give simple as I'm still green and learning to program!

Thanks in advance.

Posted 22-Apr-13 10:43am
Sergey Alexandrovich Kryukov 22-Apr-13 16:55pm
Makes no sense. Why "but"? What is "format"? What's the problem?
ryanb31 22-Apr-13 16:57pm
Usually time is just a number. It is often the number of seconds from a given fixed date and time. Assuming they are standard in .Net you can just format them as time and .Net will convert them.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The app you are using is very badly formed (or if you wrote it, you should rewrite it).

Really the only way to do this properly is to convert the times to number of seconds (even if the elapsed time is years, weeks, days, hours, minutes or already seconds) and then you can do all the sum/average/other stats that you want. For the examples you posted here, it seems that to the left of the decimal point is minutes and to the right is seconds. If this is true, you want to multiply the int cast of each by 60 and add the fraction times 100, giving total seconds.

After doing this, perhaps shoot the guy that invented that format. It has inherent error for times of (say) 0.33 and even worse for subsecond times. This would not pass any professional timing tests.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100