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. C#
  4. Converting decimal to String

Converting decimal to String

Scheduled Pinned Locked Moved C#
question
3 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.
  • S Offline
    S Offline
    Subrahmanyam K
    wrote on last edited by
    #1

    Hi, I am converting a decimal value to string for displaying it on a label. While converting the decimal value with two decimal places to string, 4 more zeroes are being appended to the decimal value. eg: "45.52" is displaying as "45.520000" on label after using the following statement: decimal d = 45.52 lblNetPrice.Text = Convert.ToString(d); What I need to do for displaying 2 decimal values on the label other than using the substring function? Thanks in advance. Subrahmanyam K

    J C 2 Replies Last reply
    0
    • S Subrahmanyam K

      Hi, I am converting a decimal value to string for displaying it on a label. While converting the decimal value with two decimal places to string, 4 more zeroes are being appended to the decimal value. eg: "45.52" is displaying as "45.520000" on label after using the following statement: decimal d = 45.52 lblNetPrice.Text = Convert.ToString(d); What I need to do for displaying 2 decimal values on the label other than using the substring function? Thanks in advance. Subrahmanyam K

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      lblNetPrice.Text = String.Format("{0:#.##}",d); /edit: helps if you get the format right -- modified at 8:05 Thursday 24th November, 2005

      1 Reply Last reply
      0
      • S Subrahmanyam K

        Hi, I am converting a decimal value to string for displaying it on a label. While converting the decimal value with two decimal places to string, 4 more zeroes are being appended to the decimal value. eg: "45.52" is displaying as "45.520000" on label after using the following statement: decimal d = 45.52 lblNetPrice.Text = Convert.ToString(d); What I need to do for displaying 2 decimal values on the label other than using the substring function? Thanks in advance. Subrahmanyam K

        C Offline
        C Offline
        Craig G Fraser
        wrote on last edited by
        #3

        Instead of this:-

        Subrahmanyam K wrote:

        decimal d = 45.52 lblNetPrice.Text = Convert.ToString(d);

        try this:- decimal d = 45.52 lblNetPrice.Text = d.ToString("###,##0.00") Cheers, Craig ** I'd rather try and fail than fail to try ;) **

        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