|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
rounding timeI'm using
label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString() courtesy of Marina to display how long a piece of code has taken. It's been less than a second so far but might go over. The only down side is I'd like this rounded to a max of say 4 decimal places. It gives me long numbers. How can I do this? "cj" <cj@nospam.nospam> schrieb Look at the documentation for the ToString method. It's overloaded.> I'm using > > label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString() > > courtesy of Marina to display how long a piece of code has taken. > It's been less than a second so far but might go over. The only > down side is I'd like this rounded to a max of say 4 decimal places. > It gives me long numbers. How can I do this? Armin I didn't find rounding any functionality in tostring. I did however
solve the problem with: label1.text = Math.Round(finishtime.Subtract(starttime).TotalSeconds, 4).ToString I'd hoped there was a method I could use instead of using the math.round function but I guess not. Armin Zingler wrote: Show quoteHide quote > "cj" <cj@nospam.nospam> schrieb >> I'm using >> >> label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString() >> >> courtesy of Marina to display how long a piece of code has taken. It's >> been less than a second so far but might go over. The only >> down side is I'd like this rounded to a max of say 4 decimal places. >> It gives me long numbers. How can I do this? > > Look at the documentation for the ToString method. It's overloaded. > > > Armin "cj" <cj@nospam.nospam> schrieb im Newsbeitrag I said you should have a look at the overloaded methods of the ToString news:%23bSQnBdTGHA.4308@TK2MSFTNGP10.phx.gbl... >I didn't find rounding any functionality in tostring. I did however solve >the problem with: > > label1.text = Math.Round(finishtime.Subtract(starttime).TotalSeconds, > 4).ToString > > I'd hoped there was a method I could use instead of using the math.round > function but I guess not. method. Armin Hello cj,
I suppose Armin was suggesting something like this: label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString("0.####") Custom Numeric Format Strings http://msdn2.microsoft.com/en-us/library/0c899ak8(VS.80).aspx Regards. Show quoteHide quote "cj" <cj@nospam.nospam> escribió en el mensaje news:%23bSQnBdTGHA.4308@TK2MSFTNGP10.phx.gbl... |I didn't find rounding any functionality in tostring. I did however | solve the problem with: | | label1.text = Math.Round(finishtime.Subtract(starttime).TotalSeconds, | 4).ToString | | I'd hoped there was a method I could use instead of using the math.round | function but I guess not. | | Armin Zingler wrote: | > "cj" <cj@nospam.nospam> schrieb | >> I'm using | >> | >> label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString() | >> | >> courtesy of Marina to display how long a piece of code has taken. It's | >> been less than a second so far but might go over. The only | >> down side is I'd like this rounded to a max of say 4 decimal places. | >> It gives me long numbers. How can I do this? | > | > Look at the documentation for the ToString method. It's overloaded. | > | > | > Armin Actually that'd be ok but I don't think that'd be rounding. I'd think
that would be truncating. José Manuel Agüero wrote: Show quoteHide quote > Hello cj, > > I suppose Armin was suggesting something like this: > label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString("0.####") > > Custom Numeric Format Strings > http://msdn2.microsoft.com/en-us/library/0c899ak8(VS.80).aspx > > Regards. > > > "cj" <cj@nospam.nospam> escribió en el mensaje news:%23bSQnBdTGHA.4308@TK2MSFTNGP10.phx.gbl... > |I didn't find rounding any functionality in tostring. I did however > | solve the problem with: > | > | label1.text = Math.Round(finishtime.Subtract(starttime).TotalSeconds, > | 4).ToString > | > | I'd hoped there was a method I could use instead of using the math.round > | function but I guess not. > | > | Armin Zingler wrote: > | > "cj" <cj@nospam.nospam> schrieb > | >> I'm using > | >> > | >> label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString() > | >> > | >> courtesy of Marina to display how long a piece of code has taken. It's > | >> been less than a second so far but might go over. The only > | >> down side is I'd like this rounded to a max of say 4 decimal places. > | >> It gives me long numbers. How can I do this? > | > > | > Look at the documentation for the ToString method. It's overloaded. > | > > | > > | > Armin You think? I don't code programs on the basis of what I think the functions do. If you follow the link I posted or the documentation Armin suggested, you won't need to make suppositions about how the formatting works.
Regards. Show quoteHide quote "cj" <cj@nospam.nospam> escribió en el mensaje news:OiciS1eTGHA.2156@tk2msftngp13.phx.gbl... | Actually that'd be ok but I don't think that'd be rounding. I'd think | that would be truncating. | | | José Manuel Agüero wrote: | > Hello cj, | > | > I suppose Armin was suggesting something like this: | > label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString("0.####") | > | > Custom Numeric Format Strings | > http://msdn2.microsoft.com/en-us/library/0c899ak8(VS.80).aspx | > | > Regards. | > | > | > "cj" <cj@nospam.nospam> escribió en el mensaje news:%23bSQnBdTGHA.4308@TK2MSFTNGP10.phx.gbl... | > |I didn't find rounding any functionality in tostring. I did however | > | solve the problem with: | > | | > | label1.text = Math.Round(finishtime.Subtract(starttime).TotalSeconds, | > | 4).ToString | > | | > | I'd hoped there was a method I could use instead of using the math.round | > | function but I guess not. | > | | > | Armin Zingler wrote: | > | > "cj" <cj@nospam.nospam> schrieb | > | >> I'm using | > | >> | > | >> label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString() | > | >> | > | >> courtesy of Marina to display how long a piece of code has taken. It's | > | >> been less than a second so far but might go over. The only | > | >> down side is I'd like this rounded to a max of say 4 decimal places. | > | >> It gives me long numbers. How can I do this? | > | > | > | > Look at the documentation for the ToString method. It's overloaded. | > | > | > | > | > | > Armin |
|||||||||||||||||||||||