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. Web Development
  3. ASP.NET
  4. Very small problem - but i had stucked here

Very small problem - but i had stucked here

Scheduled Pinned Locked Moved ASP.NET
questionhelp
12 Posts 8 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
    Satish Developer
    wrote on last edited by
    #1

    Hi friends, Its very silly problem. But still it scares me. int _Totalcnt = 62; int _Namecnt = 31; decimal Pctmatch = Convert.ToDecimal((_Namecnt / _Totalcnt) * 100); I am getting value for Pctmatch as '0'. why it showing wrong. How can i get exact decimal value there?

    G. Satish

    D L G C 4 Replies Last reply
    0
    • S Satish Developer

      Hi friends, Its very silly problem. But still it scares me. int _Totalcnt = 62; int _Namecnt = 31; decimal Pctmatch = Convert.ToDecimal((_Namecnt / _Totalcnt) * 100); I am getting value for Pctmatch as '0'. why it showing wrong. How can i get exact decimal value there?

      G. Satish

      D Offline
      D Offline
      DoctorMick
      wrote on last edited by
      #2

      Convert _Namecnt and _Totalcnt to decimals rather than the result of the calculation, i.e.

      decimal Pctmatch = (Convert.ToDecimal(_Namecnt) / Convert.ToDecimal(_Totalcnt)) * 100;

      S S 2 Replies Last reply
      0
      • D DoctorMick

        Convert _Namecnt and _Totalcnt to decimals rather than the result of the calculation, i.e.

        decimal Pctmatch = (Convert.ToDecimal(_Namecnt) / Convert.ToDecimal(_Totalcnt)) * 100;

        S Offline
        S Offline
        Spirits Soft Tech Nology Dharmapuri
        wrote on last edited by
        #3

        www.spiritssoft.com

        M A C 3 Replies Last reply
        0
        • S Satish Developer

          Hi friends, Its very silly problem. But still it scares me. int _Totalcnt = 62; int _Namecnt = 31; decimal Pctmatch = Convert.ToDecimal((_Namecnt / _Totalcnt) * 100); I am getting value for Pctmatch as '0'. why it showing wrong. How can i get exact decimal value there?

          G. Satish

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

          int _Totalcnt = 62;
          int _Namecnt = 31;

              decimal Pctmatch = Convert.ToDecimal((Convert.ToDecimal(\_Namecnt) / Convert.ToDecimal(\_Totalcnt)) \* 100);
          

          Regards Aman Bhullar www.arlivesupport.com[^]

          1 Reply Last reply
          0
          • S Satish Developer

            Hi friends, Its very silly problem. But still it scares me. int _Totalcnt = 62; int _Namecnt = 31; decimal Pctmatch = Convert.ToDecimal((_Namecnt / _Totalcnt) * 100); I am getting value for Pctmatch as '0'. why it showing wrong. How can i get exact decimal value there?

            G. Satish

            G Offline
            G Offline
            Gamzun
            wrote on last edited by
            #5

            Use Decimal directly instead of making your _Totalcnt and _Namecnt as int why taking up memory by converting them to decimal later when you can mark them decimal in first place.

            1 Reply Last reply
            0
            • S Spirits Soft Tech Nology Dharmapuri

              www.spiritssoft.com

              M Offline
              M Offline
              Manas Bhardwaj
              wrote on last edited by
              #6

              Do not spam:mad:

              Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

              1 Reply Last reply
              0
              • S Spirits Soft Tech Nology Dharmapuri

                www.spiritssoft.com

                A Offline
                A Offline
                Abhijit Jana
                wrote on last edited by
                #7

                Shivass wrote:

                www.spiritssoft.com

                Please Don't SPAM. This is second time you are doing the same thing. X|

                cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net View My Recent Article

                1 Reply Last reply
                0
                • S Satish Developer

                  Hi friends, Its very silly problem. But still it scares me. int _Totalcnt = 62; int _Namecnt = 31; decimal Pctmatch = Convert.ToDecimal((_Namecnt / _Totalcnt) * 100); I am getting value for Pctmatch as '0'. why it showing wrong. How can i get exact decimal value there?

                  G. Satish

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  I can't believe you got this many replies and not the right answer, or at least, not a proper explanation ( that I could see ). decimal PctMatch = _Namecnt/(Decimal)_Totalcnt * 100 If you divide by a decimal, you will get a decimal answer. If you divide by an int, it gets rounded and you get an int, which is THEN converted to decimal, but the decimal part has already been discarded.

                  Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                  S 1 Reply Last reply
                  0
                  • S Spirits Soft Tech Nology Dharmapuri

                    www.spiritssoft.com

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    you are a retard

                    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                    1 Reply Last reply
                    0
                    • D DoctorMick

                      Convert _Namecnt and _Totalcnt to decimals rather than the result of the calculation, i.e.

                      decimal Pctmatch = (Convert.ToDecimal(_Namecnt) / Convert.ToDecimal(_Totalcnt)) * 100;

                      S Offline
                      S Offline
                      Satish Developer
                      wrote on last edited by
                      #10

                      ya, perfect. Its working now. But how to take precesion here. i am getting value for Pctmatch = 76.876789989999 how can i get only 2 values after decimal?

                      G. Satish

                      S 1 Reply Last reply
                      0
                      • C Christian Graus

                        I can't believe you got this many replies and not the right answer, or at least, not a proper explanation ( that I could see ). decimal PctMatch = _Namecnt/(Decimal)_Totalcnt * 100 If you divide by a decimal, you will get a decimal answer. If you divide by an int, it gets rounded and you get an int, which is THEN converted to decimal, but the decimal part has already been discarded.

                        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                        S Offline
                        S Offline
                        Satish Developer
                        wrote on last edited by
                        #11

                        Thank you christian for your detailed explaination.

                        G. Satish

                        1 Reply Last reply
                        0
                        • S Satish Developer

                          ya, perfect. Its working now. But how to take precesion here. i am getting value for Pctmatch = 76.876789989999 how can i get only 2 values after decimal?

                          G. Satish

                          S Offline
                          S Offline
                          Satish Developer
                          wrote on last edited by
                          #12

                          ya, i got the answer. By converting to string as Pctmatch.ToString("N2");

                          G. Satish

                          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