Seems that line
PictureBox1.Left += And() +6
is erratic - or do you really have a function named 'And'?? If so you'll have to enclose this VB key word in square brackets like
PictureBox1.Left += [And]() +6
otherwise remove it to:
PictureBox1.Left += 6
This will move your picture box 6 pixel to the right an if resulting position exceeds 1000 pixel, the picturebox position will be reset to a default.
I'm writing a financial application , and I'm not sure about which data type to use.
I know that decimal is more precise that float , but I read that using decimal can significantly decrease the speed of calculations and the speed of storing data to database , so the speed of the application.
Is this true , and if yes is there a solution or should I continue to use float ?
Never use float (or double) for financial applications, as they are base 2 numbers and cannot accurately hold base 10 values. You can sometimes use integers, depending on the currency and values you need to represent.
I have to use a kind of data type that accept digits after decimal point.
so I need to choose between float and decimal.
But it is true that working with decimal is about 20 times slower than working with float ?
This is my question.
Thank you !
Let's try that again. We have multiple ways of displaying a number.
The Decimal[^] value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The Decimal value type is appropriate for financial calculations that require large numbers of significant integral and fractional digits and no round-off errors. The Decimal type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding. For example, the following code produces a result of 0.9999999999999999999999999999 instead of 1.
Dim dividend AsDecimal = Decimal.One
Dim divisor AsDecimal = 3' The following displays 0.9999999999999999999999999999 to the console
Console.WriteLine(dividend/divisor * divisor)
The Double[^] value type represents a double-precision 64-bit number with values ranging from negative 1.79769313486232e308 to positive 1.79769313486232e308, as well as positive or negative zero, PositiveInfinity, NegativeInfinity, and not a number (NaN). It is intended to represent values that are extremely large (such as distances between planets or galaxies) or extremely small (the molecular mass of a substance in kilograms) and that often are imprecise (such as the distance from earth to another solar system), The Double type complies with the IEC 60559:1989 (IEEE 754) standard for binary floating-point arithmetic.
That's your float in .NET.
The floating operations are faster than the decimal operations, and, if all is well, integer operations would be even faster. You keep fixing on a formatted value of $2.53 in your wallet. With some creativity you could store those as 253 cents in your database. It is impossible to work with half-a-cent, since they do not exist. No more rounding errors, and the most optimal to work with: a bigint (Int64) to store cents.
Bastard Programmer from Hell
If you can't read my code, try converting it ^]
No you don't, you need to use some creative thinking. Dave K's response above is a good illustration of why you should never use float. As to allowing the user to enter something like 450.37, that is just a string of text. You can quite easily split that into two strings and convert each one to an integer. You could then multiply the first number by 100 and add the second, to use the smallest unti type, or use them separately as dollars and cents, or rupees and paisa, whatever.
Dim f AsSingle = 123456792.0F
Dim fsw AsNew Stopwatch
For i = 1To100000000
f *= 1.00000012F
Dim dsw AsNew Stopwatch
Dim d AsDecimal = 123456792.0F
For i = 1To100000000
d *= 1.00000012F
Console.WriteLine("Float (ms): " & fsw.ElapsedMilliseconds)
Console.WriteLine("Decimal (ms): " & dsw.ElapsedMilliseconds)
Console.WriteLine("Float is " & dsw.ElapsedMilliseconds / fsw.ElapsedMilliseconds & " faster")
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.
Last Visit: 31-Dec-99 18:00 Last Update: 22-Sep-14 22:34