|
dilkonika wrote: ok , I understand why I should never choose float. ..aaah..
You should use floats when appropriate.
dilkonika wrote: But why I should not choose decimal ?
..it is slower than the non-so-precise float, but that's the trade-off. Sadly, the .NET decimal does not fit enterely into a SQL decimal.
Still accounting in cents makes more sense; as it is the mimimal nondivisible amount that the value can change.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Quote: ..it is slower than the non-so-precise float
It's very noticeable in a normal PC?
Quote: Still accounting in cents makes more sense; as it is the mimimal nondivisible amount that the value can change.
ok , but what about values like 2.672 ?
Yes , I have values like this because my application is going to work with multiple currency and the exchange rates .
Quote: Sadly, the .NET decimal does not fit enterely into a SQL decimal
Can explain with some more words this ?
Thank you !
Desimal re 20 slower than float.
An example :
Module Module1
Sub Main()
Dim f As Single = 123456792.0F
Dim fsw As New Stopwatch
fsw.Start()
For i = 1 To 100000000
f *= 1.00000012F
Next
fsw.Stop()
Dim dsw As New Stopwatch
dsw.Start()
Dim d As Decimal = 123456792.0F
For i = 1 To 100000000
d *= 1.00000012F
Next
dsw.Stop()
Console.WriteLine(f)
Console.WriteLine("Float (ms): " & fsw.ElapsedMilliseconds)
Console.WriteLine(d)
Console.WriteLine("Decimal (ms): " & dsw.ElapsedMilliseconds)
Console.WriteLine("Float is " & dsw.ElapsedMilliseconds / fsw.ElapsedMilliseconds & " faster")
Console.ReadLine()
End Sub
End Module
Results :
7.35348
Float : 306
123456800
Decimal : 6262
Float is 20.4640522875817 faster
modified 17-Sep-14 20:27pm.
|
|
|
|
|
Quote: but what about values like 2.672
You can still use integers. Multiple all values by 1000 or 10000 instead of 100.
So long as you consistently move the decimal point over the same number of places in all numbers your calculations will be accurate.
|
|
|
|
|
Sorry , but if always I use integers , why vbnet and sql servers have other data types like float or decimal ? Is better to tell to remove this kind of data type from their products because we can use integers.
|
|
|
|
|
Because they have their uses in other application types, such as scientific anaylsis where the float and double types excel more at representing numbers using scientific notation.
Don't blame Microsoft for this. They're just going by the IEEE standards for storing and representing numeric types.
Read this[^]
|
|
|
|
|
ok for float , but what about decimal ? when should they be used ?
|
|
|
|
|
Did you read the link to MSDN at all?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Yeah and it still stuffs from the same limitations.
It all depends on what you're using Excel for.
You know what. Screw this. We've said everything that's going to be said.
Use whatever you want! After all, you're the sole person that's going to have to deal with your decision.
|
|
|
|
|
Ok , ok I see that you want to close this case as soon as possible.
But I think a forum is a place for discussion.
It's just a curiosity : Microsoft has included decimal in .net language programs and Sql server.
And why he not use this kind of data type in Excel ?
Or why don't use integers that you suggest ( and to multiply all the values by 100 , 1000 , 100000 .......) and as you think everything will be better.
I have the right to be against your opinion , you can be against to my opinion .. let's discuss. This is the forum.
|
|
|
|
|
Sigh...Excel is a general purpose application, not just financial, and so must support a large range of numbers, and also balance with speed.
|
|
|
|
|
dilkonika wrote: But I think a forum is a place for discussion. It is, but this is hardly a discussion.
SQL Server and Excel were not built at the same time, nor by the same people.
dilkonika wrote: Or why don't use integers that you suggest You are making assumptions without reading, kicking against the structure claiming it is bad without taking the time to ask why it was built like that. What WHERE they thinking.
Well, you ain't gonna find out.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The difficulty appears to be arising because you are comparing speed with accuracy - two things that by their very nature cannot be compared.
So you need to decide - do you want speed or accuracy?
If you really want more information regarding why floating point is used you will need to read up on computer hardware and architecture.
Basically computers are not decimal counting machines but binary counting machines. In order to maintain a decent processing speed numbers are stored as floating point,. The consequence is that repeated arithmetic operations on large numbers(numbers with many digits either side of the decimal point) can cause precision errors. Most people not running repeated arithmetic calculations with large numbers requiring a high degree of precision - Excel works perfectly well with floating point numbers.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Quote: So you need to decide - do you want speed or accuracy?
I think any programmer in the world , try to find a way to have both of them at the better level that can be possible.
|
|
|
|
|
"If you really want more information regarding why floating point is used you will need to read up on computer hardware and architecture."
Did you read and understand that sentence?
Let's reword it - there are physical limitations to a computer that make speed and accuracy a trade-off.
You can have more speed or more accuracy but you cannot have both.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
You're really not thinking or listening.
I challenge YOU to come up with a scheme to represent a number of INFINITE size and precision on a computer with FINITE resources. There in lies the problem.
You don't mind if we don't wait around, do you? We have other things to do.
|
|
|
|
|
I have created a program, ready to deploy. I will deploy this program from a CD.
As part of the install I want to create a desktop shortcut for the program.
I am using vb2010 express and I don’t know where to start.
Thanks
Jay
|
|
|
|
|
|
I am iteration thought the row in order to insert/update/select.
How can I make Async call so it will be run faster
For Each myRow As DataRow In gobjImportDS.Tables(TABLENAME).Rows
.... If FindGIASPROVMSTR(myRow) > 0 Then
' if exists update
If GIASUpdateProviderMasterCommand(myRow) = True Then
Update(myRow)
else
Insert(myRow)
End
Next
|
|
|
|
|
Making it "async" doesn't make it run faster; it just makes it execute independently of the UI-thread. The simplest way to start something on a different thread is by queuing it in the ThreadPool[^].
Sub RunStuffAsync()
Threading.ThreadPool.QueueUserWorkItem(Sub() Bla())
End Sub
Sub Bla()
End Sub
Be carefull not to touch any UI-stuff from that new piece of code; it would crash the application, unless you wrap it nicely in an Invoke-pattern (to invoke the running of the next code on the UI-thread).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
not sure what I have done incorrect.but I it won't go to my sub.
Threading.ThreadPool.QueueUserWorkItem(Sub() modGenelco.ProcessAddChangeInGIASAsync())
Module modGenelco.....
Sub ProcessAddChangeInGIASAsync()...end sub
End Module
|
|
|
|
|
Create a new console application, and add below code;
Module Module1
Sub Main()
Console.WriteLine(Threading.Thread.CurrentThread.ManagedThreadId)
Threading.ThreadPool.QueueUserWorkItem(Sub() modGenelco.ProcessAddChangeInGIASAsync())
Console.ReadKey()
End Sub
End Module
Module modGenelco
Sub ProcessAddChangeInGIASAsync()
Console.WriteLine(Threading.Thread.CurrentThread.ManagedThreadId)
End Sub
End Module Do confirm that you have the correct module, and that the solution is rebuilt.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi all,
I'm having a problem on my code that's throwing me the following error:
'Class does not support Automation or does not support expected interface'
What I'm doing is, we have lot of ActiveX exe and we want to migrate them to .net, but as visual studio doesn't support ActiveX exe migration, I'm following this article ActiveX EXE Wrappers[^] I did one test project and after this worked I tried to migrate a working project.
So I was migrating my ActiveX exe to a Windows forms Application and I adde the following com class to my projec:
clsCom.vb
<ComClass(clsCom.ClassId, clsCom.InterfaceId, clsCom.EventsId)> _
Public Class clsCom
#Region "COM GUIDs"
Public Const ClassId As String = "5f6daa91-519d-4db0-a71a-83a2cc5980cc"
Public Const InterfaceId As String = "dfc3f83c-38a8-43e5-98d1-6914983a9df1"
Public Const EventsId As String = "5ed06d44-d6b6-431b-8804-2ef2a0fb1b70"
#End Region
Public Sub New()
End Sub
Public Shared Sub Main()
End Sub
Public Sub Amend(ByRef lPOSID As Integer)
Dim clsentry As New clsEntry
clsentry.Amend(lPOSID)
End Sub
Public Sub View(ByRef lPOSID As Integer)
Dim clsentry As New clsEntry
clsentry.View(lPOSID)
End Sub
Public Sub Add(ByRef lPOSID As Integer)
Dim clsentry As New clsEntry
clsentry.Add(lPOSID)
End Sub
Public Sub Delete(ByRef lPOSID As Integer)
Dim clsentry As New clsEntry
clsentry.Delete(lPOSID)
End Sub
End Class
After this I created my VB6 to call my Com Object:
Option Explicit
Public placeOfSet As gdcPlaceOfSettlement.clsCom
Public Sub Main()
Set placeOfSet = New gdcPlaceOfSettlement.clsCom
placeOfSet.Amend (5654)
End Sub
The error is ocurring at: Set placeOfSet = New gdcPlaceOfSettlement.clsCom
I don't know what's going on, I've checked few websites and none of them matches with my thread.
Does anyone had the same problem or knows how to fix it?
Thanks in advance.
|
|
|
|
|
If you download the code from the article, and use
Dim MyMsgNet
Set MyMsgNet = CreateObject("MsgNet.ComExpose")
MyMsgNet.StartApplication to instantiate your .NET class from VB6, does it work?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
hey Eddy,
I'm using this test as a template, but still geting the same error
|
|
|
|