|
-
Nov 4th, 2007, 09:53 AM
#1
Thread Starter
Fanatic Member
-
Nov 4th, 2007, 10:28 AM
#2
Re: Rounding issues ???? or Not !!
Rounding is probably depending on the pc's processor and the exact value of .5 is the culprit when converting decimal to non-decimal data types. A decision has to be made: is .5 rounded down or rounded up. Different processors, different rules? But the rule that appears to be used is whether or not the whole number is even or odd - crappy rule, huh? Honestly I thought VB did the tie-breaker but between your system & my system, we got different values (are we both running VB SP6?). Rounding all other decimal values are determined by being > or < .5
Things to look for. Anything where you convert a decimal value to a non-decimal variable type. Anything? Huh?, Yep, the following will return the same value. Horrible
Code:
? cint(31.5);cint(32.5)
Obviously, when working with decimal types, it is best to not convert back and forth. Building your own rounding rule may help too, basically deciding beforehand if .5 will be rounded down or up if the decimal portion is exactly .5
Last edited by LaVolpe; Nov 4th, 2007 at 10:37 AM.
-
Nov 4th, 2007, 11:08 AM
#3
Thread Starter
Fanatic Member
Re: Rounding issues ???? or Not !!
First, yes I am running VB6 SP6
I use a lot of Doubles in my app’s but when I store them in my database I convert them into text and then when I load my app I convert them back into doubles
Using CDbl() & CStr()
Is this the type of thing that may cause me problems 
Or is it only when using whole numbers
-
Nov 4th, 2007, 11:11 AM
#4
Re: Rounding issues ???? or Not !!
Can't see how. CStr() does no conversion to integer/long. CDbl() & Val() return double values when used on a string's value.
Edited: When db is used, why not store them in a data field appropriate for doubles. Double uses 8 bytes, whereas a string uses 1 to 2 bytes per character (ansi vs unicode). Do all dbs store strings in 2 byte format?
Last edited by LaVolpe; Nov 4th, 2007 at 11:14 AM.
-
Nov 4th, 2007, 11:13 AM
#5
Thread Starter
Fanatic Member
Re: Rounding issues ???? or Not !!
So the problem is only when dividing whole numbers and getting a decimal answer ???
-
Nov 4th, 2007, 11:20 AM
#6
Thread Starter
Fanatic Member
-
Nov 4th, 2007, 11:21 AM
#7
Re: Rounding issues ???? or Not !!
 Originally Posted by JohnSavage
So the problem is only when dividing whole numbers and getting a decimal answer ???
No, the problem is when converting decimal numbers to byte, integer, long only when the decimal portion is exactly .5
VB's Round() function suffers from say problem: ? Round(31.5); Round(32.5) along with integer division (\) and any function that expects a non-decimal value
-
Nov 4th, 2007, 11:26 AM
#8
Thread Starter
Fanatic Member
-
Nov 4th, 2007, 11:29 AM
#9
Thread Starter
Fanatic Member
Re: Rounding issues ???? or Not !!
the problem is when converting decimal numbers to byte, integer, long only when the decimal portion is exactly .5
OK now I understand - thank for your time AGAIN !!
-
Nov 4th, 2007, 11:31 AM
#10
Re: [RESOLVED] Rounding issues ???? or Not !!
John, take a look at this link from developerfusion -- a nice site.
-
Nov 4th, 2007, 11:40 AM
#11
Thread Starter
Fanatic Member
-
Nov 4th, 2007, 10:38 PM
#12
Re: [RESOLVED] Rounding issues ???? or Not !!
Hey John,
Binary is binary, even if you encrypted 1001111010011101010100011100
if you stored it in a double it would still be a double. No need to convert to a string... Am I missing something?
-
Nov 5th, 2007, 06:26 AM
#13
Thread Starter
Fanatic Member
Re: [RESOLVED] Rounding issues ???? or Not !!
Randem
My encryption routine makes an encrypted text string therefore if I tried to save it to a database field of type Double then I would get an error.
Now as a result of this, all of my field types are text and therefore when I get a record from my database I have to use:
Code:
IJR = CDbl(Encrypt(RS1.Fields("32").Value, Key))
Which first de-encyrpts it and then changes it back to a double
or similar
But I could be wrong again 
If there is a strong encryption rountine that works regardless of data type then that would make my life at the keyboard a whole lot less complicated
Last edited by JohnSavage; Nov 5th, 2007 at 06:37 AM.
-
Nov 5th, 2007, 01:25 PM
#14
Re: [RESOLVED] Rounding issues ???? or Not !!
Good Encryption routines should not care about data type. As I stated all data is binary. So encrypting a 8 byte double field would still yield 8 bytes or less and can be stored in the same data type.
-
Nov 5th, 2007, 06:15 PM
#15
Thread Starter
Fanatic Member
Re: [RESOLVED] Rounding issues ???? or Not !!
Randem
You say:
“Good Encryption routines should not care about data type. As I stated all data is binary. So encrypting an 8 byte double field would still yield 8 bytes or less and can be stored in the same data type”
I am sure you are correct but how does this statement help me?
You have a link in your signature “String Encryption” is that not good then?
All I can do is repeat:
If there is a strong encryption routine that works regardless of data type then please tell me were to find it as it would make things a lot easier for me.
-
Nov 5th, 2007, 09:12 PM
#16
Re: [RESOLVED] Rounding issues ???? or Not !!
The link in my signature doesn't care about text, it's a binary string which can contain any binary signature.
Ex.
Take a long say, &FFFF then AND it with &1111 (Basically Encrypting it). It still stays a Long and can be stored as such. You don't need to turn it into a string first then save it as a string or text field.
-
Nov 6th, 2007, 06:35 AM
#17
Thread Starter
Fanatic Member
Re: [RESOLVED] Rounding issues ???? or Not !!
Many thanks - I was under the impression that you did have to give the function a string and then convert it back !
But that just about sums up my VB knowledge!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|