473,795 Members | 2,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Math function

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
Nov 21 '05 #1
3 1603
On 2004-10-07, Agnes <ag***@dynamict ech.com.hk> wrote:
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/de...l/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
--
Tom Shelton [MVP]
Nov 21 '05 #2
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
"Tom Shelton" <to*@YOUKNOWTHE DRILLmtogden.co m> ¦b¶l¥ó
news:uh******** ******@TK2MSFTN GP09.phx.gbl ¤¤¼¶¼g...
On 2004-10-07, Agnes <ag***@dynamict ech.com.hk> wrote:
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/de...l/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
--
Tom Shelton [MVP]

Nov 21 '05 #3
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.Truncat e, 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

"Agnes" <ag***@dynamict ech.com.hk> wrote in message
news:O7******** *****@tk2msftng p13.phx.gbl... 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
"Tom Shelton" <to*@YOUKNOWTHE DRILLmtogden.co m> ¦b¶l¥ó
news:uh******** ******@TK2MSFTN GP09.phx.gbl ¤¤¼¶¼g...
On 2004-10-07, Agnes <ag***@dynamict ech.com.hk> wrote:
> 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/de...l/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
--
Tom Shelton [MVP]


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2543
by: barnesc | last post by:
Hi! Here's a simple hashcash implementation in Python. 28 lines of actual code. Can be reduced to 17 lines for instructional purposes, if you don't want clustering, and use xrange() instead of irange().
2
1659
by: Senraba | last post by:
I would like to have a 600 X 400 window open with search results from CPanel's Entropy Search form. I have the following in the <HEAD> tag: <script language="javascript" type="text/javascript"> <!-- var win=null; function NewWindow(mypage,myname,w,h,scroll,pos){ if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
17
3629
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels deep. In that case you need much more ram than a PC has to store functions calculated in loops so that you do not have to recalculate every time you cycle through the nest of loops. Using a HD for storage to extend ram is much too slow for many...
32
5125
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 * 10^12) it's pretty efficient, it took 15 minutes to compute the first 1,000,000 primes.
3
2148
by: vezquex | last post by:
What I want is an element with a shifting background image: <html><head> <script type="text/javascript"> var x = 0 var y = 0 inc = 4 function bgWander(el){ x = x + Math.round(2*inc*Math.random())-inc y = y + Math.round(2*inc*Math.random())-inc
14
1463
by: helpfulmaid | last post by:
Hello, I want a function that when it detects the left mouse button is pressed down, will generate and cycle 5 random number/letter combinations as fast as it can in a printed space. If I let off the mouse button then it should stop, and it can re-start again when pressed, etc..... can someone help help? :-)
5
1719
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to insert a weight converter into my survey. Unfortunately this script works fine in firefox v.2 but does not cooperate with the surveymonkey software when used with internet explorer v.6. Can someone explain to me in simple terms why the script...
22
2800
by: giordan | last post by:
Hi all! I've wrote this code: <script type="text/javascript"> var largImg; var altImg; var txtTop = '<b>Ottima scelta!</b> Ora compila il form e premi "Ricevi banner". Il codice HTML ti verrà mostrato in questa pagina e, per comodità, ti verrà inviato, via mail, all\'indirizzo da te fornito. Se invece vuoi cambiare il banner premi "Seleziona banner"'; var txtButton = 'Cambia banner'; var testo = '';
1
2077
by: astrogirl77 | last post by:
I'm new to C++ and am hoping to find help with coding a simple C program, am wanting to obtain code and functioning exe's. I code in an old version of Visual Basic 4.0, I have a simple app that is about 3 and a half pages of code long it does some relatively simple math additions and subtractions The problem I have is that some numbers get to be very large integers and VB automatically converts this to scientifc notation, what I need is...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.