kelley80209
Programmer
Hi All,
I am trying to display numbers as they appear in the database. For example, weight is a single field. If the user puts in 31.1, I want to display 31.1, but the report shows 31.10.
I have used the following formula to display only the decimals that are actually there.....
if isnull({ado.weight}) OR Len(Cstr({ado.weight})) = 0 then
" "
else
StringVar text := Totext ( {ado.weight} , 4, "" ) ;
NumberVar end := length ( text ) ;
NumberVar clip :=
(if Val ( text [ end - 4 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 3 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 2 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 1 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 0 to end ] ) = 0 then 1 else 0 ) ;
text [ 1 to Length ( text ) - clip ] & " kg"
This works fine if there is data in the weight field. If the value is actually null, I get the following error: "A subscript must be between 1 and the length of the string".
Based on this error, it appears that the 'else' statement is being executed. This is not the case. If I replace the code with the following, a blank is displayed.......
if isnull({ado.weight}) OR Len(Cstr({ado.weight})) = 0 then
" "
else
"This is the weight: " & {ado.weight}
Any help would be much appreciated. This is frustrating since it seems CR randomly put 2 decimals on all numeric fields. Grrrrr.
Thanks in advance,
Kelley
I am trying to display numbers as they appear in the database. For example, weight is a single field. If the user puts in 31.1, I want to display 31.1, but the report shows 31.10.
I have used the following formula to display only the decimals that are actually there.....
if isnull({ado.weight}) OR Len(Cstr({ado.weight})) = 0 then
" "
else
StringVar text := Totext ( {ado.weight} , 4, "" ) ;
NumberVar end := length ( text ) ;
NumberVar clip :=
(if Val ( text [ end - 4 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 3 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 2 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 1 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 0 to end ] ) = 0 then 1 else 0 ) ;
text [ 1 to Length ( text ) - clip ] & " kg"
This works fine if there is data in the weight field. If the value is actually null, I get the following error: "A subscript must be between 1 and the length of the string".
Based on this error, it appears that the 'else' statement is being executed. This is not the case. If I replace the code with the following, a blank is displayed.......
if isnull({ado.weight}) OR Len(Cstr({ado.weight})) = 0 then
" "
else
"This is the weight: " & {ado.weight}
Any help would be much appreciated. This is frustrating since it seems CR randomly put 2 decimals on all numeric fields. Grrrrr.
Thanks in advance,
Kelley