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. Formatting a number

Formatting a number

Scheduled Pinned Locked Moved C#
tutorial
6 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.
  • N Offline
    N Offline
    N Surendra Prasad
    wrote on last edited by
    #1

    is it possible to format the number 150000 to 1,50,000. I tried formatting using DataformatString but, it displays 150,000. Do anyone know how to format a number to indian currency. N.Surendra Prasad

    K D 2 Replies Last reply
    0
    • N N Surendra Prasad

      is it possible to format the number 150000 to 1,50,000. I tried formatting using DataformatString but, it displays 150,000. Do anyone know how to format a number to indian currency. N.Surendra Prasad

      K Offline
      K Offline
      Krazy Programmer
      wrote on last edited by
      #2

      U need to count number of digits and place the , accordingly There may be other alternatives .. for a quick fix try the above

      If You win You need not Explain............ But If You Loose You Should not be there to Explain......

      1 Reply Last reply
      0
      • N N Surendra Prasad

        is it possible to format the number 150000 to 1,50,000. I tried formatting using DataformatString but, it displays 150,000. Do anyone know how to format a number to indian currency. N.Surendra Prasad

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        This[^] is in VB but may help.

        Dave

        N 1 Reply Last reply
        0
        • D DaveyM69

          This[^] is in VB but may help.

          Dave

          N Offline
          N Offline
          N Surendra Prasad
          wrote on last edited by
          #4

          Do you have any sample on how to use this?

          D 2 Replies Last reply
          0
          • N N Surendra Prasad

            Do you have any sample on how to use this?

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            The full thread is here[^] - there's an explaination of the code at the bottom by the author.

            Dave

            1 Reply Last reply
            0
            • N N Surendra Prasad

              Do you have any sample on how to use this?

              D Offline
              D Offline
              DaveyM69
              wrote on last edited by
              #6

              Having looked in more detail I think that thread is a little over-complicated. Why not use the CultureInfo class? If you're going to be using it alot it could be useful to set it as an extension method something like this.

              using System.Globalization;

              namespace Indian
              {
              public static class ExtMethods
              {
              public static string ToIndian(this double amount, bool includePrefix)
              {
              CultureInfo indianCulture = new CultureInfo("hi-IN");
              string indianString = amount.ToString("C", indianCulture);
              if (includePrefix)
              {
              return indianString;
              }
              return indianString.Substring(2);
              }
              }
              }

              then add using Indian; to the beginning of any class that needs it. You can then easily call the method on any double value (change it to other value type if required!).

              double doubleIndian = 1234567.89;
              string stringIndian = doubleIndian.ToIndian(false);

              Dave

              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