|
-
Dec 1st, 2012, 09:03 AM
#4
Re: Formatting A Number
 Originally Posted by Yumby
Thanks TJ. I tried variations of your code and this....
Code:
MessageBox.Show(New TimeSpan(Convert.ToInt64(2.5 * TimeSpan.TicksPerMinute)).ToString)
This code got me 00:02:30
But with my formatting (as per the request in the OP) it returns 02:30:000 as it was supposed to.
 Originally Posted by Yumby
But this code....
Code:
MessageBox.Show(New TimeSpan(Convert.ToInt64(dursonchr * TimeSpan.TicksPerMinute)).ToString)
This got me 00:00:00.1190475
In my program, dursonchr is 0.001984125. And the way I get it is this....
Code:
Dim dursonchr
dursonchr = dursonmat / 60 / 24
So any ideas about where I'm going wrong?
1) You should use Option Explicit - declaring a variable without type is not the most readable (or efficient, intuitive etc.).
2) I have to assume that dursonmat is a floating point variable containing a portion of a day, so small that it can be counted in 2-digit minutes, 2-digit seconds and 3-digit miliseconds (due to the fact that you divide it by 24, getting hours, and then 60getting minutes). If not your first post dosen't make much sense (ie. anything higher will yield a format of xxxx:yy:zzz, which pretty much is unreadable and should have hours added). And if it is indeed as small as assumed, my code in post #2 will do exactly as you requested.
Tom
#EDIT: You are possibly expecting a result of 02:51:428, in which case, you should just use my original code with dursonmat replacing m.
Last edited by ThomasJohnsen; Dec 1st, 2012 at 09:16 AM.
In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|