Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Add zero to the front of a number

Add zero to the front of a number

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viettho
    wrote on last edited by
    #1

    Hi, i'm doing a project and I need to add 0 to the front of a number. Is there a way to format a number? for example: 898 become 000898 If anyone could help me, I would appriciate. Thank you.

    D T O 3 Replies Last reply
    0
    • V viettho

      Hi, i'm doing a project and I need to add 0 to the front of a number. Is there a way to format a number? for example: 898 become 000898 If anyone could help me, I would appriciate. Thank you.

      D Offline
      D Offline
      Dennis C Dietrich
      wrote on last edited by
      #2

      viettho wrote: Hi, i'm doing a project and I need to add 0 to the front of a number. Is there a way to format a number? for example: 898 become 000898 I assume you have some kind of variable where you store your number. Let's also assume this variable is an Int32 (Integer in Visual Basic). The easiest way is to use the method Int32.ToString(String)[^] and pass an appropriate NumberFormatInfo[^].

      Dim myInt As Integer = 898
      MessageBox.Show(myInt.ToString("D6"))

      Best regards Dennis

      V 1 Reply Last reply
      0
      • D Dennis C Dietrich

        viettho wrote: Hi, i'm doing a project and I need to add 0 to the front of a number. Is there a way to format a number? for example: 898 become 000898 I assume you have some kind of variable where you store your number. Let's also assume this variable is an Int32 (Integer in Visual Basic). The easiest way is to use the method Int32.ToString(String)[^] and pass an appropriate NumberFormatInfo[^].

        Dim myInt As Integer = 898
        MessageBox.Show(myInt.ToString("D6"))

        Best regards Dennis

        V Offline
        V Offline
        viettho
        wrote on last edited by
        #3

        thank you..it works.

        1 Reply Last reply
        0
        • V viettho

          Hi, i'm doing a project and I need to add 0 to the front of a number. Is there a way to format a number? for example: 898 become 000898 If anyone could help me, I would appriciate. Thank you.

          T Offline
          T Offline
          Tom John
          wrote on last edited by
          #4

          An alternate solution is to use the format function to ensure a number has an enforced number of characters: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctFormat.asp[^]

          Dim i As Integer = 898
          MsgBox(Format(i, "00000#"))

          Hope this helps Tom

          1 Reply Last reply
          0
          • V viettho

            Hi, i'm doing a project and I need to add 0 to the front of a number. Is there a way to format a number? for example: 898 become 000898 If anyone could help me, I would appriciate. Thank you.

            O Offline
            O Offline
            OICU812
            wrote on last edited by
            #5

            Example: Dim X As Integer = 827 TextBox1.Text = Format(x, "000000").ToString

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups