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. double to string without point [SOLVED]

double to string without point [SOLVED]

Scheduled Pinned Locked Moved C#
22 Posts 10 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.
  • P Pierre besquent

    Hi everybody, I wanna have the smallest code to conver a double to a string without the point of digits Exple: 12.010 --->1201 ty

    modified on Friday, March 18, 2011 6:03 AM

    D Offline
    D Offline
    Dave Kreskowiak
    wrote on last edited by
    #2

    The only way you're going to "have" is to write it yourself. We're not going to write it for you, and frankly, this can be done in a single line of code. ...and this reeks of being a homework assignment.

    A guide to posting questions on CodeProject[^]
    Dave Kreskowiak

    F 1 Reply Last reply
    0
    • P Pierre besquent

      Hi everybody, I wanna have the smallest code to conver a double to a string without the point of digits Exple: 12.010 --->1201 ty

      modified on Friday, March 18, 2011 6:03 AM

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #3

      By "smallest" what do you mean? Does your homework need the fewest number of characters? The shortest IL? The quickest execution? Or what?

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      L 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        By "smallest" what do you mean? Does your homework need the fewest number of characters? The shortest IL? The quickest execution? Or what?

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #4

        using (Font f=new Font("Courier New", 0.01)) {
        // normal code goes here
        }

        :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        1 Reply Last reply
        0
        • P Pierre besquent

          Hi everybody, I wanna have the smallest code to conver a double to a string without the point of digits Exple: 12.010 --->1201 ty

          modified on Friday, March 18, 2011 6:03 AM

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #5

          (anti)hint: NumberFormat.DecimalSeparator does not accept an empty string. :)

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          1 Reply Last reply
          0
          • P Pierre besquent

            Hi everybody, I wanna have the smallest code to conver a double to a string without the point of digits Exple: 12.010 --->1201 ty

            modified on Friday, March 18, 2011 6:03 AM

            P Offline
            P Offline
            Paladin2000
            wrote on last edited by
            #6

            That is an unusual requirement. However:

            double d = 12.010;

            string s = Math.Truncate(d * 100).ToString();

            P F 2 Replies Last reply
            0
            • P Paladin2000

              That is an unusual requirement. However:

              double d = 12.010;

              string s = Math.Truncate(d * 100).ToString();

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #7

              Or

              d.ToString().Replace('.', string.Empty);

              So many ways to do it, and as usual, the requirements exist in a fug of inadequacy.

              I'm not a stalker, I just know things. Oh by the way, you're out of milk.

              Forgive your enemies - it messes with their heads

              My blog | My articles | MoXAML PowerToys | Onyx

              L 1 Reply Last reply
              0
              • P Pete OHanlon

                Or

                d.ToString().Replace('.', string.Empty);

                So many ways to do it, and as usual, the requirements exist in a fug of inadequacy.

                I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Onyx

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #8

                I'm sorry to say, I see two problems with that: 1. it doesn't compile as Replace needs (char,char) or (string,string); 2. cultural differences may cause some other character to act as decimal point, a comma for instance. So I'd suggest d.ToString(NumberFormatInfo.InvariantInfo).Replace(".", ""); as the proper way to do it, and possibly ""+(int)(100*d) as the shortest code (with overflow risks). :)

                Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                P 1 Reply Last reply
                0
                • L Luc Pattyn

                  I'm sorry to say, I see two problems with that: 1. it doesn't compile as Replace needs (char,char) or (string,string); 2. cultural differences may cause some other character to act as decimal point, a comma for instance. So I'd suggest d.ToString(NumberFormatInfo.InvariantInfo).Replace(".", ""); as the proper way to do it, and possibly ""+(int)(100*d) as the shortest code (with overflow risks). :)

                  Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #9

                  Don't be sorry. You are right after all.

                  I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                  Forgive your enemies - it messes with their heads

                  My blog | My articles | MoXAML PowerToys | Onyx

                  L 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    Don't be sorry. You are right after all.

                    I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                    Forgive your enemies - it messes with their heads

                    My blog | My articles | MoXAML PowerToys | Onyx

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #10

                    Well, I do am sorry in a different way, as I didn't find a way to signal your code's weakness without violating Dave's hint not to answer homework questions in any detail. That must be the price to pay when coming late to a thread. :)

                    Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                    P 1 Reply Last reply
                    0
                    • P Pierre besquent

                      Hi everybody, I wanna have the smallest code to conver a double to a string without the point of digits Exple: 12.010 --->1201 ty

                      modified on Friday, March 18, 2011 6:03 AM

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      Pierre besquent wrote:

                      I wanna have

                      ..you want fries with that? :)

                      I are Troll :suss:

                      L 1 Reply Last reply
                      0
                      • L Lost User

                        Pierre besquent wrote:

                        I wanna have

                        ..you want fries with that? :)

                        I are Troll :suss:

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #12

                        yes please, as long as they don't add points. :)

                        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                        1 Reply Last reply
                        0
                        • P Pierre besquent

                          Hi everybody, I wanna have the smallest code to conver a double to a string without the point of digits Exple: 12.010 --->1201 ty

                          modified on Friday, March 18, 2011 6:03 AM

                          P Offline
                          P Offline
                          PIEBALDconsult
                          wrote on last edited by
                          #13

                          You might need a file for that.

                          L 1 Reply Last reply
                          0
                          • P PIEBALDconsult

                            You might need a file for that.

                            L Offline
                            L Offline
                            Luc Pattyn
                            wrote on last edited by
                            #14

                            please make sure there is no period in the filename! :-D

                            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                            P 1 Reply Last reply
                            0
                            • D Dave Kreskowiak

                              The only way you're going to "have" is to write it yourself. We're not going to write it for you, and frankly, this can be done in a single line of code. ...and this reeks of being a homework assignment.

                              A guide to posting questions on CodeProject[^]
                              Dave Kreskowiak

                              F Offline
                              F Offline
                              fjdiewornncalwe
                              wrote on last edited by
                              #15

                              What... You need a WHOLE line. I could do it in 1/3 of a line... :)

                              I wasn't, now I am, then I won't be anymore.

                              D 1 Reply Last reply
                              0
                              • P Paladin2000

                                That is an unusual requirement. However:

                                double d = 12.010;

                                string s = Math.Truncate(d * 100).ToString();

                                F Offline
                                F Offline
                                fjdiewornncalwe
                                wrote on last edited by
                                #16

                                Not as silly as you may think. I worked on a project once where the client provided long lists of products with decimal based prices, but where the database was setup to hold prices based in cents, not decimal dollars. A crappy design it was, but hands were tied they were.

                                I wasn't, now I am, then I won't be anymore.

                                1 Reply Last reply
                                0
                                • F fjdiewornncalwe

                                  What... You need a WHOLE line. I could do it in 1/3 of a line... :)

                                  I wasn't, now I am, then I won't be anymore.

                                  D Offline
                                  D Offline
                                  Dave Kreskowiak
                                  wrote on last edited by
                                  #17

                                  I'll do it in a 1/3 of a line at 640x480. If you want to beat that, you'll have to "name that tune"!

                                  A guide to posting questions on CodeProject[^]
                                  Dave Kreskowiak

                                  F 1 Reply Last reply
                                  0
                                  • L Luc Pattyn

                                    Well, I do am sorry in a different way, as I didn't find a way to signal your code's weakness without violating Dave's hint not to answer homework questions in any detail. That must be the price to pay when coming late to a thread. :)

                                    Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                                    Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                                    P Offline
                                    P Offline
                                    Pete OHanlon
                                    wrote on last edited by
                                    #18

                                    The reason I posted mine is because, weaknesses from typing it up on a phone keyboard notwithstanding, it's a poor way of solving the problem - and then you went and corrected it. I ignored various edge cases, which you started to correct - shame on you ;P .

                                    I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                                    Forgive your enemies - it messes with their heads

                                    My blog | My articles | MoXAML PowerToys | Onyx

                                    P 1 Reply Last reply
                                    0
                                    • L Luc Pattyn

                                      please make sure there is no period in the filename! :-D

                                      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                                      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                                      P Offline
                                      P Offline
                                      Pierre besquent
                                      wrote on last edited by
                                      #19

                                      thank u for all, u really let me laughing very much with all u jokes responses :laugh: that is the real help I found a solution my self:

                                      double x = 1458752.10254000;
                                      string s = x.ToString(System.Globalization.CultureInfo.InvariantCulture).Replace(".",string.Empty);
                                      Console.WriteLine(s);
                                      Console.ReadLine();

                                      the output is :145875210254 thank u very much for u big effort in creating jokes. :laugh:

                                      1 Reply Last reply
                                      0
                                      • P Pete OHanlon

                                        The reason I posted mine is because, weaknesses from typing it up on a phone keyboard notwithstanding, it's a poor way of solving the problem - and then you went and corrected it. I ignored various edge cases, which you started to correct - shame on you ;P .

                                        I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                                        Forgive your enemies - it messes with their heads

                                        My blog | My articles | MoXAML PowerToys | Onyx

                                        P Offline
                                        P Offline
                                        Pierre besquent
                                        wrote on last edited by
                                        #20

                                        always insulting me thank u for u help :laugh:

                                        1 Reply Last reply
                                        0
                                        • D Dave Kreskowiak

                                          I'll do it in a 1/3 of a line at 640x480. If you want to beat that, you'll have to "name that tune"!

                                          A guide to posting questions on CodeProject[^]
                                          Dave Kreskowiak

                                          F Offline
                                          F Offline
                                          fjdiewornncalwe
                                          wrote on last edited by
                                          #21

                                          The current one playing is Lennon's version of Stand by Me, but I sing it I'll clear the room.

                                          I wasn't, now I am, then I won't be anymore.

                                          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