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

Retrieving Whole Number from a Decimal without Rounding? 5

Status
Not open for further replies.

antonio622

Programmer
Jun 10, 2007
20
0
0
US
I have a variable declared as Single and I am trying to retrieve only the whole number without rounding up or down as in the following number:

3.959

I only want to assign 3 in the number above to another variable.

If I do this in code using format number and read only the whole number of course I get the value of 4.

Is there a command or procedure in VB.net to disable rounding off numbers in one instance?
 
And yet another method:

Dim a As Single = 3.42765
Dim b As Single
Dim c As Integer

b = a Mod 1 'the portion after the decimal
c = a - b 'the integer portion

MsgBox(a)
MsgBox(b)
MsgBox(c)

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top