How to convert an int to a string with a fixed point?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Sargent
    New Member
    • Jan 2011
    • 6

    How to convert an int to a string with a fixed point?

    I'm trying to output a time. I have an int representing the hours and the minutes. Both need to be two digits, and they need to be output as string variables.

    How do I output the numbers with two places?
    For example, assume that
    int hour = 8, int minute = 5
    I need to make string timeOutput = 8:05
    I thought it was
    timeOutput = ("{0:D2}:{1:D2} ", hour, minute);
    But that doesn't work.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    You've almost got it, you're just missing the call to string.Format.

    Code:
    timeOutput = [b]string.Format[/b]("{0:D2}:{1:D2}", hour, minute);

    Comment

    Working...