Home All Groups Group Topic Archive Search About
Author
21 Mar 2006 7:56 PM
cj
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?

Author
21 Mar 2006 8:28 PM
Armin Zingler
"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
Author
22 Mar 2006 4:48 PM
cj
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
Author
22 Mar 2006 6:53 PM
Armin Zingler
"cj" <cj@nospam.nospam> schrieb im Newsbeitrag
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.

I said you should have a look at the overloaded methods of the ToString
method.

Armin
Author
22 Mar 2006 7:55 PM
José_Manuel_Agüero
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
Author
22 Mar 2006 8:15 PM
cj
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
Author
22 Mar 2006 10:51 PM
José_Manuel_Agüero
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