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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return whole number after division 1

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hello
I am looking for a way to return the whole number only after doing a division.

Example 1905/60 = 31.75, I want to return only the 31. How can I do this?

I have tried
Code:
Math.Round(31.75) [green]//returns 32[/green]
I need to keep the exactly number, no rounding. What I have done temporarily was this

Code:
(1905/60).ToString().Split('.')[0]; [green]//returns 31[/green]

Is there a System.Math method I can use to avoid converting to a string?

Thanks.
 
double dbl = 31.75;
Console.WriteLine(Math.Truncate(dbl));


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I am using .net 1.1, I read that Truncate is only available in 3.0.
 
Truncate is available in 2.0. Here is a 1.1 solution now that I know that is a limitation:

double dbl=31.75;
Console.WriteLine(Math.Floor(dbl));

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Console.WriteLine((int)dbl);

or

Console.WriteLine(Convert.ToInt32(dbl));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top