tehon3299 Posted April 29, 2003 Posted April 29, 2003 How can I get an integer NOT to round? i.e. 1.88 I want to be 1 and not round up to 2. Or should it be a double? If so, I do I now show the decimal places? Quote Thanks, Tehon
*Experts* Nerseus Posted April 29, 2003 *Experts* Posted April 29, 2003 In C# you just cast as an int, and it never rounds. Try: decimal i = 1.88M; Debug.WriteLine((int)i); I don't know the equivalent in VB.NET, if you need it just ask. -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
tehon3299 Posted April 29, 2003 Author Posted April 29, 2003 Thanks...I know how to do it in VB..Thanks again Quote Thanks, Tehon
*Gurus* Derek Stone Posted April 30, 2003 *Gurus* Posted April 30, 2003 Decimal.Floor() is the non-language oriented (and dare I say correct method) of rounding down a decimal value to the nearest whole number. Quote Posting Guidelines
hog Posted April 30, 2003 Posted April 30, 2003 I use this: intWhatEver = Convert.ToInt32(Math.Floor(1.88)) Quote My website
*Experts* Nerseus Posted April 30, 2003 *Experts* Posted April 30, 2003 You guys are mostly right - assuming you are using positive numbers. Floor behaves differently for negative numbers. If you do Math.Floor(-1.88) you'll get 2 (weird, but true). To do that properly using the math functions, you need to check for < 0 and use Math.Ceiling. Casting as (int) works in both cases. -Ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.