Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jpiscit1
Posting Yak Master
130 Posts |
Posted - 2004-03-25 : 13:51:06
|
Can anyone tell me why my negative values knock off a decimal when I perform the same exact calculation on a postive value? Here's what I have:A form with 5 text boxes. Text box (TextWeightPickup) represents a net (delta) value of weight in kg. - text box is linked to SQL tableText box (TextUSLKg) represents USL (upper spec Limit) in kg. - text box is linked to SQL tableText box (TextLSLKg) represents LSL (Lower spec Limit) in kg. - text box is linked to SQL tableText box (TextUSL) represents USL (Upper spec Limit) in %. - text box is NOT linked to SQL table - Enabled property = NOText box (TextLSL) represents LSL (Lower spec Limit) in %. - text box is NOT linked to SQL table - Enabled property = NOThe user would enter in a value for TextWeightPickup. He/She would then entire in a value for the TextUSLKg and the TextLSLKg. here would be an example of what is entered:TextWeightPickup = 0.783TextUSLKg = .030TextLSLKg = -.030 Note: negative value representing lower specification limit.Here my problem:I am running a calculation on the boxes TextUSL and TextLSL that would display the kg USL/LSL in terms of percent. But no matter what I do the calculation for the negative keeps knocking of a decimal place. Here is the calculation I am using:=([TextUSLKg]/[TextWeightPickup])*100You would assume (.030/0.783)*100 = 3.83%and (-.030/0.783)*100 = -3.83%But I am getting:USL (+) 3.83LSL (-) 3.8If the calculation product was 3.86 the value in LSL would be 3.9 which implies it is rounding.Now, I have already verified that the related SQL fields are formated properly and that the Text box Format is not on Auto (does the same thing when it is on) and instead set for 2. Although I have tried 3, 4, 5, etc.What might be going on here? Does MS Access have a problem with Negative values ????Thanks in Advance.John |
|
KnooKie
Aged Yak Warrior
623 Posts |
Posted - 2004-03-29 : 09:33:37
|
have you tried using the FORMAT function ?====Paul |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-03-29 : 09:44:54
|
never do math using textbox values without making sure you are explicitly converting them to the type that you need.Never say: [text1] / [text2]always use: Ccur([Text1]) / Ccur([Text2])or whatever it is you need. text1 is a VARIANT, which means there's much implicit converting and rounding that you will not be aware of or able to control. Even if it appears to work w/o the conversions, always try to use them because some value with inexplicity show up (as in your case) which will cause your code to somehow magically stop working.also: rememebr that just becuase you have the textbox formatted to be 3.8 doesn't mean that 3.8 will be used in the calculation -- the actual value may be 3.7638462533 which is what will really be used. - Jeff |
 |
|
|
|
|