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
  1. Home
  2. General Programming
  3. Visual Basic
  4. The correct way to format a number

The correct way to format a number

Scheduled Pinned Locked Moved Visual Basic
helptutorial
4 Posts 2 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.
  • M Offline
    M Offline
    Mark06
    wrote on last edited by
    #1

    Hi everyone, I was wondering, what would be the correct way of formatting a number, based on regional settings. For example: Dim value as double = 123456.78 Label1.Text = value The label would show: 123456.78 I need it to show: 123,456.78 if I'm in the UK 123.456,78 if I'm in Europe I'm sure its a simple Format problem. Just cant remember. Any ideas Mark

    G 1 Reply Last reply
    0
    • M Mark06

      Hi everyone, I was wondering, what would be the correct way of formatting a number, based on regional settings. For example: Dim value as double = 123456.78 Label1.Text = value The label would show: 123456.78 I need it to show: 123,456.78 if I'm in the UK 123.456,78 if I'm in Europe I'm sure its a simple Format problem. Just cant remember. Any ideas Mark

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Use the format string "N2" to format the number. It will give you the correct format for the current regional settings.

      Mark06 wrote:

      123,456.78 if I'm in the UK 123.456,78 if I'm in Europe

      Last time I checked UK was still part of Europe. ;)

      --- single minded; short sighted; long gone;

      M 1 Reply Last reply
      0
      • G Guffa

        Use the format string "N2" to format the number. It will give you the correct format for the current regional settings.

        Mark06 wrote:

        123,456.78 if I'm in the UK 123.456,78 if I'm in Europe

        Last time I checked UK was still part of Europe. ;)

        --- single minded; short sighted; long gone;

        M Offline
        M Offline
        Mark06
        wrote on last edited by
        #3

        But how do I should I use it? I tried Label1.text = String.Format(value, "N2") and it didnt work. As for Europe, appologies, I meant countries like Germany represent decimals and thousand seperators differently to UK.

        G 1 Reply Last reply
        0
        • M Mark06

          But how do I should I use it? I tried Label1.text = String.Format(value, "N2") and it didnt work. As for Europe, appologies, I meant countries like Germany represent decimals and thousand seperators differently to UK.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Tip: "didnt work" is not a very good problem description. ;) Use it like this: Label1.text = value.ToString("N2") or like this: Label1.text = String.Format("{0:N2}", value)

          --- single minded; short sighted; long gone;

          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