473,426 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 software developers and data experts.

weird integer rounding error

hi guys why does this

Dim x As Integer
Dim y As Double

y = 4.664
x = Convert.ToInt32(y)

give me x=5 ?????

surely it should be 4

it doesnt matter what conversion i do all my integers round up if above .5 and down if below .5

any ideas ? ? ? ?
Nov 27 '07 #1
2 1140
Mohan Krishna
115 100+
:
:
any ideas ? ? ? ?
Hi

Why don't u use INT()?

ALL THE BEST!
Nov 27 '07 #2
Killer42
8,435 Expert 8TB
What this code is doing is rounding. From the sound of it, you don't want rounding, you want truncation. As Mohan mentioned, the Int() function may be the way to go. (This applies to VB6 - not sure about your version.)
Nov 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ai lian | last post by:
The code is as the following: { double limit= 0.02*33.00; double limit1= 0.06*11.00; double limit2= 0.03*22.00; double limit3= 0.01*66.00; limit=(floor(limit*100))/100;...
20
by: Pascal Gallois | last post by:
Hi newsgroup, I am new to C and wonder about the following code: #include <stdio.h> int main(void) { double m = 100.45; double n = 200.45;
9
by: Mikael Svenson | last post by:
Sample code: static void Main(string args) { double inf = 0.1 / 0.0; int test2 = (int)(inf * 0.0F); Console.WriteLine( test2.ToString() ); } On a P3 this gives the result "0", on a P4 it...
38
by: baong | last post by:
dear all i have use this line to time in many my web base appl. but now i found a weird problem the javascript line is the same but i use the calculation 2 time @ the first time, it is ok, 3 *...
10
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
8
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the...
18
by: atv | last post by:
at least to me it is. I can't figure out for the life what it is i'm doing wrong here. i have a function called assign_coordinate. usually, i pass a malloced pointer to it, then individual...
10
by: alsmeirelles | last post by:
Hi all, I Have run this test: Private Sub test() Dim d As Double Dim f As Single Dim output As String d = 8888888888888.8887
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
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...

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.