Packed/zoned decimals not working correctly
Decimal aren't working as expected with packed and zoned numbers. If I give number 100 to 5p2 it becomes 1.00 when parsed.
I made some tests for this problem.
$ ./test1000_sql400json32 ../json/j0030_decimal_numbers1
input(5000000):
{"pgm":[{"name":"DECIMALS", "lib":"DB2JSON"},
{"s":[
{"name":"afloat", "type":"4f2", "value":1000},
{"name":"adouble", "type":"8f3", "value":1000},
{"name":"apacked", "type":"12p2", "value":1000},
{"name":"azoned", "type":"12s2", "value":1000}
]}
]}
output(118):
{"script":[{"pgm":["DECIMALS","DB2JSON",{"afloat":1000.00},{"adouble":1000.000},{"apacked":10.00},{"azoned":10.00}]}]}
result:
fail missing ("apacked":1000.00)
fail (-1)
Comments (7)
-
Account Deleted -
reporter Thanks, almost there.
When giving too many decimals it still breaks.
$ ./test1000_sql400json64 ../json/j0033_decimal_numbers4 input(5000000): {"pgm":[{"name":"DECIMALS", "lib":"DB2JSON"}, {"s":[ {"name":"afloat", "type":"4f2", "value":1000.000}, {"name":"adouble", "type":"8f3", "value":1000.0000}, {"name":"apacked", "type":"12p2", "value":1000.000}, {"name":"azoned", "type":"12s2", "value":1000.000} ]} ]} output(124): {"script":[{"pgm":["DECIMALS","DB2JSON",{"afloat":1000.00},{"adouble":1000.000},{"apacked":10000.00},{"azoned":10000.00}]}]} result: fail missing ("apacked":1000.00) fail (-1)
-
Account Deleted Ok, try again. Thanks.
- Link Text - test driver - 1.1.4-sg8 toolkit - more packed and zoned too large input (Halmela)
Side note ...
I could not decide extra digits past max scale should round up. Anyway, I just truncated anything past field scale size.
- "value":12.49999 == truncates 12.49 (12p2 or 12s2).
Opinion?
-
reporter This looks good.
I'm fine with truncation. Maybe a note should be added to the readme about this behavior.
-
Account Deleted round
Mm ... add round to avoid note about truncation behaviour (coin flip). Only one place in source (PaseToIle.c), can be easily removed, should rounding prove unpopular or defective.
- Yips Super Driver - test driver - 1.1.4-sg10 - toolkit - added input round packed/zoned
bash-4.3$ ./test1000_sql400json32 ../json/j08324_srvpgm_value_rainpack24-2_mix_decimal input(5000000): {"pgm":[{"name":"RAINSRV", "lib":"DB2JSON", "func":"RAINPACK24"}, {"s":[{"name":"a1", "type":"24p2", "value":11., "by":"val"}, {"name":"a2", "type":"24p2", "value":00000000000000000000000022.0, "by":"val"}, {"name":"a3", "type":"24p2", "value":12345678912345678912345678933.309999999999, "by":"val"}, {"name":"a4", "type":"24p2", "value":44.040, "by":"val"}, {"name":"o1", "type":"24p2", "value":55.55}, {"name":"o2", "type":"24p2", "value":66.66}, {"name":"o3", "type":"24p2", "value":77.77}, {"name":"o4", "type":"24p2", "value":88.88} ]} ]} output(199): {"script":[{"pgm":["RAINSRV","DB2JSON","RAINPACK24", {"a1":11.00},{"a2":22.00}, {"a3":8912345678912345678933.31}, {"a4":44.04},{"o1":11.00},{"o2":22.00}, {"o3":8912345678912345678933.31}, {"o4":44.04}]}]} result: success (0)
-
Account Deleted Are we done with this issue? We still pondering more fate of packed and zoned decimal round vs. truncation?
-
reporter - changed status to resolved
This is done.
- Log in to comment
Ok, I have a fix seems to work for packed and zoned. Thanks.