05-12-2005 5:35 PM
this is probably very easy, but i couldn't find the information I need yet.
I have a field in my db-table with type P (length 9, decimal places 3).
when i copy a value with 3 decimal places (e.g. 1,234) into the field, I want to remove the last digit (4), so the result should be 1,23. How do I do this without changing the data type and lenght of the field?
05-12-2005 6:03 PM
If your field is defined as type p decimals 3, then that is the format that it will take in the database. If you want to display this value in a program a different way, then you should use the following logic.
Data: x type p decimals 3 value '1.234'.
Data: y type p decimals 2.
y = x.
Write:/ x.
Write:/ y.
Regards,
Rich Heilman
05-12-2005 6:03 PM
If your field is defined as type p decimals 3, then that is the format that it will take in the database. If you want to display this value in a program a different way, then you should use the following logic.
Data: x type p decimals 3 value '1.234'.
Data: y type p decimals 2.
y = x.
Write:/ x.
Write:/ y.
Regards,
Rich Heilman
05-12-2005 6:04 PM
Hello Daniel,
that depends wether you want to have truncation or not. If you would like to have the number rounded up you simply can define an intermeditate variable. Else the use of the statement trunc should help.
Best Regards
Klaus
program test.
write: / ' CAST'. perform cast using : '1.011', '2.036'.
write: / 'TRUNC'. perform trunc using : '1.011', '2.036'.
form cast using value type p.
data:
3decs type p length 9 decimals 3,
2decs type p length 9 decimals 2.
3decs = value.
write : 3decs.
3decs = 2decs = 3decs.
write : 3decs.
endform.
form trunc using value type p.
data:
3decs type p length 9 decimals 3.
3decs = value.
write : 3decs.
3decs = ( trunc( 100 * 3decs ) / 100 ).
write : 3decs.
endform.
05-13-2005 7:08 AM