The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
[VB]Math.Floor: Why Return a Double? RRS feed

  • General discussion

  • The Math.Floor function, a very basic function used to round a number down, returns a Double. Why would anybody want this? But more interestingly, if you look at Intellisense (as shown in the following screenshot):

    You will notice that it says "Returns the largest integer". The word "integer" may not be capitalized like it would be in code, but I still find it somewhat strange why they would give a rounding function that requires manual conversion to an Integer.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Wednesday, November 6, 2019 2:59 AM

All replies

  • conversion takes time. If you want you can convert the result yourself, but it does not make sense to have everyone else pay the cost, especially when the result will be used in expressions where it has to be converted back to double first. 

    besides, the value range for a double is way larger than an int. if you limit the result to be in int range, then you have to validate the double parameter (maybe throw an exception when the result cannot be represented by int) before doing the actual flooring. This is another cost that I am pretty sure a lot of people are not willing to pay. 



    Visual C++ MVP

    Wednesday, November 6, 2019 6:27 AM
  • I guess those are good enough reasons. I often use it to calculate the Grid.Row & Grid.Column in my UWP, so I always need to convert it to Integer, but I guess when it is just being used as a mathematical value (meaning type is not significant, when you don't care whether you use 1.0 or 1) it is more efficient to skip the conversion.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Wednesday, November 6, 2019 3:30 PM