Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Math.Floor Or else?

Status
Not open for further replies.

abs2003

MIS
Aug 31, 2004
80
US
Hi everyone,
How can round numbers like..

10.1 to 10
10.4 to 10
10.5 to 10
10.7 to 10
10.0 to 10

Yes, I can use Math.Floor. But it won't work with converting 10.0 to 10.

Any idea?

Thank you
 
You could always use int e.g.
Code:
Dim i As Integer = Int("10.6")


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks guys,
I solved my problem by adding .001 to the number before using floor function.

example
Code:
dim newNumber as integer
dim oldNumber as double= 10.0


newNumber = Math.Floor(oldNumber + .001)

This will return number of 10.

The reason, if you call Floor function with parameter as 10.0, it will return 9. I sure don't understand why Microsoft did this.
 
And what happens when you come across this scenario:
Code:
        Dim newNumber As Integer
        Dim oldNumber As Double = 10.999
        newNumber = Math.Floor(oldNumber + 0.001)
and your newNumber returns 11?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
10.0 is equal to 10. Just use Math.Floor and format your number for display however you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top