Simple Math function

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

my number is 100.1 , Now I only want to get 100 without any round up or
round down function,
Can anyone told me which function can do that ?
Thanks
 
my number is 100.1 , Now I only want to get 100 without any round up or
round down function,
Can anyone told me which function can do that ?
Thanks

You'll want to look at the Int or the Fix function - depending on how
you want negative number handled. Here are the remarks from the
function reference:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctint.asp
Remarks

Both the Int and Fix functions remove the fractional part of number and
return the resulting integer value.

The difference between Int and Fix functions is that if number is
negative, Int returns the first negative integer less than or equal to
number, whereas Fix returns the first negative integer greater than or
equal to number. For example, Int converts -8.4 to -9, and Fix converts
-8.4 to -8.

Fix(number) is equivalent to Sign(number) * Int(Abs(number)).

HTH
 
Thanks Tom, now, How can I get "1"
Dim decCent As Decimal = 100.3- Int(100.3) , now decCent get 0.29999999999
but not 0.3
Please help
 
Agnes,
100.3 is not a Decimal number its a double, try:
Dim decCent As Decimal = 100.3D - Int(100.3D) , now decCent get
0.29999999999

The D after 100.3 indicates it is a Decimal literal, not a Double literal.

In addition to Int & Fix that Tom suggested, there are Decimal.Floor,
Decimal.Truncate, Math.Floor, Math.Ceiling & possible other methods on
either Decimal, Math, Single, Double.

For an explanation of the differences between a Decimal & Double see:

http://www.yoda.arachsys.com/csharp/floatingpoint.html
http://www.yoda.arachsys.com/csharp/decimal.html

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top