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. C#
  4. Percent Formatting

Percent Formatting

Scheduled Pinned Locked Moved C#
helpquestionlounge
4 Posts 3 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.
  • D Offline
    D Offline
    Drew McGhie
    wrote on last edited by
    #1

    I love all the random formatting that is provided, but I'm having an issue with the default percent formatting. I databind a decimal value in a dataset to a textbox, and set the default formatting to "#,##0.##%" The problem is my end-user is slightly annoyed with the resulting format. If the end user inputs 2.34 (with their interpretation of 2.34%), it formats itself to "234%". If the end-user wants to end up with a display of "2.34%", he needs to entier either that, or .0234. My question is simply this, is there a way to override the percent formatting, or another custom string taht I can use that won't automatically do the "multiply by 100" in the format?

    N G 2 Replies Last reply
    0
    • D Drew McGhie

      I love all the random formatting that is provided, but I'm having an issue with the default percent formatting. I databind a decimal value in a dataset to a textbox, and set the default formatting to "#,##0.##%" The problem is my end-user is slightly annoyed with the resulting format. If the end user inputs 2.34 (with their interpretation of 2.34%), it formats itself to "234%". If the end-user wants to end up with a display of "2.34%", he needs to entier either that, or .0234. My question is simply this, is there a way to override the percent formatting, or another custom string taht I can use that won't automatically do the "multiply by 100" in the format?

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      I can think of another way to do it, but it's a bit longer: 1- Create the text box. 2- Parse it into a float to validate the input 3- Format the float with your desired format into a string 4- Do whatever you want with that string The code I used is like this: float test = float.Parse(textBox1.Text); MessageBox.Show(test.ToString("#,###.##") + "%");

      1 Reply Last reply
      0
      • D Drew McGhie

        I love all the random formatting that is provided, but I'm having an issue with the default percent formatting. I databind a decimal value in a dataset to a textbox, and set the default formatting to "#,##0.##%" The problem is my end-user is slightly annoyed with the resulting format. If the end user inputs 2.34 (with their interpretation of 2.34%), it formats itself to "234%". If the end-user wants to end up with a display of "2.34%", he needs to entier either that, or .0234. My question is simply this, is there a way to override the percent formatting, or another custom string taht I can use that won't automatically do the "multiply by 100" in the format?

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

        Use apostrophes in the format string to specify literal text: "#,##0.##'%'" --- b { font-weight: normal; }

        D 1 Reply Last reply
        0
        • G Guffa

          Use apostrophes in the format string to specify literal text: "#,##0.##'%'" --- b { font-weight: normal; }

          D Offline
          D Offline
          Drew McGhie
          wrote on last edited by
          #4

          That did it, thanks.

          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