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. Are you good with Maths API

Are you good with Maths API

Scheduled Pinned Locked Moved C#
helpjsonquestion
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.
  • H hasanali00

    I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks

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

    Math.Round( (a / 10) + .5 ) ? David

    1 Reply Last reply
    0
    • H hasanali00

      I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #3

      How about (int)((n+9)/10) ? You can even skip the (int) if your n already is an int... mav

      1 Reply Last reply
      0
      • H hasanali00

        I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks

        R Offline
        R Offline
        Roger Wright
        wrote on last edited by
        #4

        Not knowing C# I can't give you the proper code, but in pseudo-code: If (x - int(x)) > 0.00 return int(x) + 1 else return int(x) Unlike the rounding function, which will round down as well as up, this will return either the original input, if it is an integer, or the next higher integer if it contains any fractional part at all. You may still get some goofy errors, though, because the input might have some small fractional part due to previous calculations. There are ways to get around that, but they may not be necessary depending upon your application. "...putting all your eggs in one basket along with your bowling ball and gym clothes only gets you scrambled eggs and an extra laundry day... " - Jeffry J. Brickley

        1 Reply Last reply
        0
        • H hasanali00

          I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #5

          Math.Ceiling(a / 10);


          www.troschuetz.de

          1 Reply Last reply
          0
          • H hasanali00

            I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks

            D Offline
            D Offline
            Daniel Monzert
            wrote on last edited by
            #6

            gee *cough* I'll join, assuming x is an int.. int n = (x / 10) + (x % 10 > 0 ? 1 : 0); *lame around* \o/

            D 1 Reply Last reply
            0
            • D Daniel Monzert

              gee *cough* I'll join, assuming x is an int.. int n = (x / 10) + (x % 10 > 0 ? 1 : 0); *lame around* \o/

              D Offline
              D Offline
              Daniel Monzert
              wrote on last edited by
              #7

              While walking at the abyss of insanity, I found out, you can use something completely senseless, far away from anything that could be called useful. Evalute strings. int x = 27; int n = 0; string seperator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; double d = ((double)x / 10.0d); string s = d.ToString("F1"); if (!s.Substring(s.IndexOf(seperator) + 1, 1).Equals("0")) { d += 1.0d; s = d.ToString("F1"); } n = int.Parse(s.Substring(0, s.IndexOf(seperator)));

              M S D 3 Replies Last reply
              0
              • D Daniel Monzert

                While walking at the abyss of insanity, I found out, you can use something completely senseless, far away from anything that could be called useful. Evalute strings. int x = 27; int n = 0; string seperator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; double d = ((double)x / 10.0d); string s = d.ToString("F1"); if (!s.Substring(s.IndexOf(seperator) + 1, 1).Equals("0")) { d += 1.0d; s = d.ToString("F1"); } n = int.Parse(s.Substring(0, s.IndexOf(seperator)));

                M Offline
                M Offline
                mav northwind
                wrote on last edited by
                #8

                Daniel, you frighten me! ;) mav

                1 Reply Last reply
                0
                • H hasanali00

                  I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks

                  N Offline
                  N Offline
                  Niklas Ulvinge
                  wrote on last edited by
                  #9

                  Wouldn't this be machinecode optimised: n >> 1; n /= 5; n++; In asm it would be like: ;number in AL SHL AL,1 ;2 clocks MOV BL, 5 ;4 clocks DIV BL ;0-90 clocks INC AX ;2 clocks (saved one clock by using AX insted of AL...) ; ;I'm not familiar with how much the div instruction takes in time but ;since it is only 5 I think's it's not much. ; The PROgrammer Niklas Ulvinge aka IDK

                  1 Reply Last reply
                  0
                  • D Daniel Monzert

                    While walking at the abyss of insanity, I found out, you can use something completely senseless, far away from anything that could be called useful. Evalute strings. int x = 27; int n = 0; string seperator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; double d = ((double)x / 10.0d); string s = d.ToString("F1"); if (!s.Substring(s.IndexOf(seperator) + 1, 1).Equals("0")) { d += 1.0d; s = d.ToString("F1"); } n = int.Parse(s.Substring(0, s.IndexOf(seperator)));

                    S Offline
                    S Offline
                    StylezHouse
                    wrote on last edited by
                    #10

                    You are outta control! ;P

                    1 Reply Last reply
                    0
                    • D Daniel Monzert

                      While walking at the abyss of insanity, I found out, you can use something completely senseless, far away from anything that could be called useful. Evalute strings. int x = 27; int n = 0; string seperator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; double d = ((double)x / 10.0d); string s = d.ToString("F1"); if (!s.Substring(s.IndexOf(seperator) + 1, 1).Equals("0")) { d += 1.0d; s = d.ToString("F1"); } n = int.Parse(s.Substring(0, s.IndexOf(seperator)));

                      D Offline
                      D Offline
                      Daniel Monzert
                      wrote on last edited by
                      #11

                      Umm.. yes, I got it out of the abyss of insanity, I'm walking quite close to it but usually don't use anything from there :D Even if it works, it's awful, but it works :D I also like the ASM version from Niklas Ulvinge :)

                      1 Reply Last reply
                      0
                      • H hasanali00

                        I wonder if u can help me in solving the following problem: I want to divide a number by 10 and get the result as the highest number. Let me explain with following examples: 13/10 = 2 and 27/10 = 3 How can I achieve this thanks

                        H Offline
                        H Offline
                        hasanali00
                        wrote on last edited by
                        #12

                        Thanks for many ideas. This is what worked for me: Math.Ceiling(13.0D / 10.0D); Only if the values inside Ceiling(...) are Double and not int

                        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