|
CCG3 wrote: Doesn't MidpointRounding.AwayFromZero fix what you are refering to?
No, it doesn't. It just happened to change the behavior of the Round method so THAT particular case worked out properly. The AwayFromZero option rounds numbers up, never down.
CCG3 wrote: And now my return is .03 just as I would expect it to be. I am only asking because accuracy is important and it seems to be pretty accurate as of now. But are you saying if I had 1.255 / 100 then it wouldn't be accurate?
Yep. The only reason why it worked is because the math using Double numbers worked out to nice even binary representations. For example, 1.255 / 100 = 0.012549999999999, not 0.01255. In your case, 2.5 / 100 worked out evenly to 0.025. It's those binary approximations that screws up the rounding. It just happened to work out properly on the example you tried. It will NOT work in all cases.
You'd probably be better off using the Decimal type instead of Double.
|
|
|
|
|
Thanks Dave, I think I understand what you are saying...
on further testing, I ran these lines just like this...
Dim DisTest As Double = 1.255 / 100
MsgBox(DisTest)
DisTest = Round(DisTest, 2, MidpointRounding.AwayFromZero)
MsgBox(DisTest)
Dim DisTest2 As Decimal = 1.255 / 100
MsgBox(DisTest2)
DisTest2 = Round(DisTest2, 2)
MsgBox(DisTest2)
They both gave the same results. (.01)
And you are saying that I would be better off to just use Decimal. The preceeding example is all I would have to change right? Instead of using Double change it to Decimal and leave out the MidpointRounding.AwayFromZero. right?
|
|
|
|
|
Yep. But, only your testing is going to tell you if it's appropriate or not. Remember, there is a performance hit for using the Deicmal type.
|
|
|
|
|
|
That's because 1.255 / 100 = .01255
Rounding to 2 places *IS* .01
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Dim DisTest as Double = 2.5/100
DisTest= (Int((DisTest + 0.005) * 100)) / 100
The secret is in the 0.005.
0.001 + 0.005 = 0.006, * 100 = 0.6, int = 0, / 100 = 0.00
0.002 + 0.005 = 0.007, * 100 = 0.7, int = 0, / 100 = 0.00
0.003 + 0.005 = 0.008, * 100 = 0.8, int = 0, / 100 = 0.00
0.004 + 0.005 = 0.009, * 100 = 0.9, int = 0, / 100 = 0.00
0.005 + 0.005 = 0.010, * 100 = 1.0, int = 1, / 100 = 0.01
0.006 + 0.005 = 0.011, * 100 = 1.1, int = 1, / 100 = 0.01
0.007 + 0.005 = 0.012, * 100 = 1.2, int = 1, / 100 = 0.01
0.008 + 0.005 = 0.013, * 100 = 1.3, int = 1, / 100 = 0.01
0.009 + 0.005 = 0.014, * 100 = 1.4, int = 1, / 100 = 0.01
0.010 + 0.005 = 0.015, * 100 = 1.5, int = 1, / 100 = 0.01
etc
Also, I don't use "Round" because I can never remember from language to language how it works (round up? round down? round on .5?)
If I want to round .005 down, .006 up (standard practise), I use 0.004 instead of 0.005
|
|
|
|
|
Hi all.
I am drawing a form and i have changed its property as
form1.borderstyle=none
I hv created my own border and controls to handle form but boundries of form are not bold as it seems in a bordered form.
I want to make boundries of form bold with having same property of form (means borderless form).
Thanks.
Gagan
|
|
|
|
|
Your question seems to be a bit jumbled. You have created a borderless form that allows interaction (minimize, maximize, close) through custom controls. Now, based on what I understand, can you make the question a bit more clear?
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
As i said, i have created a borderless form and use my custom controls to minimize,maximize and close form.
I just want to make boundries of my form bold. (as in a bordered form)
Thanks.
Gagan
|
|
|
|
|
This can be done in a variety of ways. Image background, panel with 3D styles, custom control form borders, etc.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Hi Friends, I am unable to Implement This line of Code of Vb6 in Visual Studio means Vb.Net because .Net does not support Pset Method...
picImage.PSet (r, c), RGB(clrr, clrg, clrb)
where r and c are radom points of picture....
Any body plz Guide me...........
|
|
|
|
|
You should make clear what you want to do. what is this picImage.
Is it a picturebox or an image control.
|
|
|
|
|
PIcimage is a picturebox and clrr = red Color,clrg = green color,clrb=blue......
|
|
|
|
|
I am assuming that the picImage is a Bitmap object (at least when transferred to VB.NET).
You should be able to use the SetPixel method:
picImage.SetPixel(r,c,new Color(clrr,clrg,clrb));
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Dear this line of code giving me this error...
picImage.SetPixel(r,c,new Color(clrr,clrg,clrb));
Error is:
"Type System.drawing.color has no constructs"
and picimage is a bitmap........
|
|
|
|
|
Oops,
Color.FromARGB(clrr,clrg,clrb)
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Thanks dear It realy worked thx Alot
|
|
|
|
|
Dear Gents,
I have an electronic weighing scale connected to the PC. I can read the weight thru hyper terminal with the help of tcp/ip. (IP address: 192.168.5.5 and port number:23).
How can i access the same using vb.net
Please help me to acheive this
Regards
Azeem
|
|
|
|
|
I am not too familiar with terminal usage, but at first glance I would say emulation. I believe terminal is basically a command prompt window. Simply create a new terminal with Process.Start, and redirect the input and output to your application. Input would be the commands that you type to get the scale information, output would be what the application responds with that would be sent to your application.
[Edit:Look into the startup info properties for the Process class.]
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Google for a "tcp/ip terminal emulation library" you can use. It's either that or you're going to have to write one yourself using the System.Net namespace.
|
|
|
|
|
write a application for tcp-client, then connect to your terminal IP,Port
You can get the data on your tcp-client socket.
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
Hello everyone...
I have developed a windows application using vb.net in visual studio2005.The backend was sql server2000.Now when i try to run the exe file of the project in another machine which has .net framework installed in it, i am getting the following error.
'System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'
Even though there is SQL server2005 packaged with visual studio 2005, i created the database in sqlserver 2000.I tried changing the prerequisities of the project deployment by including sqlserver2005 in prerequisities list...but that too isn't working....Now what should i do to run the project in other machine...........plz could anyone help me out.................
|
|
|
|
|
Hi
you seem to be having connection issue, your app cannot access the sql db.
1.
you connectionstring property may be incorrect....
2.
check to see if sql server accepts incomming connections
use the sql2005 connection manager and enable the various options...
hope this helps
Anoop Brijmohun
|
|
|
|
|
There is no problem with connection string bcoz the application has no problems in execution in visual studio ide. the problem happens wen the exe file of the application is executed in another machine. i have tried enabling remote connections of sqlserver2005 in configuration manager. one thing to be noted is that the datatbase is being created in sqlserver2000.
|
|
|
|
|
The sql2000 db should not be the cause of the error.
i have used applications that was created in sql2000 and attached it to sql2005 and works fine from other pcs.
System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'
once again make sure you named pipe protocol is enabled
ps. did you restart the sql 2005 service after enabling all protocols?
thanks
|
|
|
|
|