473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Formatting Numbers

I am running into a weird problem. I am using the following code:

String.Format("{0:0}:{1:00}:{2:00}", Hours.ToString, Minutes.ToString,
Seconds.ToString)

Just say seconds is set to 1, it should return a string that displays
0:00:01, but it isn't display that, instead I get 0:0:1. Can anyone tell me
why the format function isn't displaying both digit placeholders? 00 as a
format should return 01, not 1. Any ideas?
Nov 21 '05 #1
2 1382
"Mark" <Ma**@discussions.microsoft.com> schrieb:
I am running into a weird problem. I am using the following code:

String.Format("{0:0}:{1:00}:{2:00}", Hours.ToString, Minutes.ToString,
Seconds.ToString)

Just say seconds is set to 1, it should return a string that displays
0:00:01, but it isn't display that, instead I get 0:0:1. Can anyone tell
me
why the format function isn't displaying both digit placeholders? 00 as a
format should return 01, not 1. Any ideas?


Remove the 'ToString'. Formatting will work with /numbers/, not /strings/.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Mark,
In addition to the other comments.

Rather then try to format hour, minute, second variables as independent
variables I find it easier to use DataTime & TimeSpan variables. As they
provide built-in formatting as well as reduce the number of variables I am
using.

Something like:

Dim hours As Integer = 0
Dim minutes As Integer = 0
Dim seconds As Integer = 1

Dim theTime As New TimeSpan(hours, minutes, seconds)
Dim s As String

s = theTime.ToString()

Note TimeSpan itself only supports a fixed format, I will convert a TimeSpan
into a DateTime if I need custom formatting.

s = String.Format("{0:H:mm:ss}", DateTime.MinValue.Add(theTime))

For details on custom datetime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp
Hope this helps
Jay
"Mark" <Ma**@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
I am running into a weird problem. I am using the following code:

String.Format("{0:0}:{1:00}:{2:00}", Hours.ToString, Minutes.ToString,
Seconds.ToString)

Just say seconds is set to 1, it should return a string that displays
0:00:01, but it isn't display that, instead I get 0:0:1. Can anyone tell
me
why the format function isn't displaying both digit placeholders? 00 as a
format should return 01, not 1. Any ideas?

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan Sommers | last post by:
Hi, I have a class whose objects represent physical quantities including uncertainties and units, and I would like more control over the way they print. I have a __str__ method which outputs...
4
by: Tommi Mäkitalo | last post by:
Hi I need to format floating-point-numbers with exact 2 digits after decimal point. I could use printf with "%.2f", but it don't use std::locale. Any ideas? -- Tommi Mäkitalo
4
by: Dave Brydon | last post by:
Access 2003 I have a combo box in my personnel table, which draws its data from a trade code table; the original field in the code table, is numeric, Long Integer, and formatted with 5 zero's . ...
4
by: John Sutor | last post by:
I need some code that, on each keyup event, will take all of the numbers typed into the text box and format as they type to look like this 100 1,000 10,000 100,000 1,000,000 John S
7
by: ilona | last post by:
Hi all, I store phone numbers in the database as 123447775665554(input mask is used for input, and some numbers have extensions), and I also know from db if the number is Canadian, US, or some...
9
by: Markus | last post by:
Hi all, two questions on formatting numbers: - Given is a decimal/money datatype in SQL-Server, e.g. decimal(9,4), thus displaying a value like 13.2000 How can I prevent to display the...
5
by: Carla | last post by:
I have Access 2000. I made a mailing list database and for the life of me can't remember how to format the zip code field so it will print on the label as xxxxx-xxxx. I have tried various - 9, #,...
6
by: Rafael Olarte | last post by:
The goal of this project is to output the following information as follows: 34.5 38.6 4.1 42.4 3.8 close 46.8 4.4 big change. The values of the first colunm are obtain from a file...
2
by: jerryyang_la1 | last post by:
I need some advice on formatting numbers using PHP. My database holds numbers like: 10 0.2 I need these to be displayed as 10.00
3
by: sparks | last post by:
We have one database that they are constantly reformatting their inputs. I asked about the changes and they can never get the same types of numbers from the people. some are -.95 and later they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.