complete newbie

  • Thread starter Thread starter jlab13
  • Start date Start date
J

jlab13

how do you get an integer answer to be returned rounded? i.e. 9.10
instead of 9.98888, etc.

Thanks for any help!!
 
how do you get an integer answer to be returned rounded? i.e. 9.10
instead of 9.98888, etc.

Thanks for any help!!

Assuming you are using VB.NET, check into the Math.Round method in the
Math Class.
 
Assuming you are using VB.NET, check into the Math.Round method in the
Math Class.

Also not the MidPointRounding parameter in some of the overloads for
Math.Round. If you don't specify this parameter it defaults to ToEven
which may give you unexpected results.

i.e.

Math.Round(5.05, 1) ' Returns 5.0
Math.Round(5.05, 1, MidpointRounding.ToEven) ' Returns 5.0
Math.Round(5.05, 1, MidpointRounding.AwayFromZero) ' Returns 5.1

Thanks,

Seth Rowe
 
Hello jlab13,
how do you get an integer answer to be returned rounded? i.e. 9.10
instead of 9.98888, etc.

First of all some clarification:
An integer does not have fractions, but is only a natural number: 1, 2,
3, 4, ...

For numbers with fractions you can use either Single, Double or Decimal
datatype.


So, assuming that you use either Single, Double or Decimal:
If you want to display it on the screen, then you might want to use the
"Format" function like this:

Dim a As Single = 1.23948583

MsgBox (Format(a, "0.00"))
'shows: 1.24

Best regards,

Martin
 
dude a friggin integer doesn't have decimal places

isnt it just .ToInt

ROFL

it should be, but M$ is not capable of 'delivering a complete story'
 
Back
Top