加载脚本
Num 可用在加载脚本中以格式化数字,即使千分位和小数位分隔符已经在脚本中设置。下面的加载脚本包括特定的千分位和小数位分隔符,但之后使用 Num 来以不同方式格式化数据。
在数据加载编辑器中,创建新的部分,然后添加示例脚本并运行它。然后,至少要将结果列中列出的字段添加到应用程序中的表格才能查看结果。
SET ThousandSep=',';
SET DecimalSep='.';
Transactions:
Load
*,
Num(transaction_amount) as [No formatting],
Num(transaction_amount,'0') as [0],
Num(transaction_amount,'#,##0') as [#,##0],
Num(transaction_amount,'# ###,00') as [# ###,00],
Num(transaction_amount,'# ###,00',',',' ') as [# ###,00 , ',' , ' '],
Num(transaction_amount,'#,###.00','.',',') as [#,###.00 , '.' , ','],
Num(transaction_amount,'$#,###.00') as [$#,###.00],
;
Load * Inline [
transaction_id, transaction_date, transaction_amount, transaction_quantity, discount, customer_id, size, color_code
3750, 20180830, 12423.56, 23, 0,2038593, L, Red
3751, 20180907, 5356.31, 6, 0.1, 203521, m, orange
3752, 20180916, 15.75, 1, 0.22, 5646471, S, blue
3753, 20180922, 1251, 7, 0, 3036491, l, Black
3754, 20180922, 21484.21, 1356, 75, 049681, xs, Red
3756, 20180922, -59.18, 2, 0.333333333333333, 2038593, M, Blue
3757, 20180923, 3177.4, 21, .14, 203521, XL, Black
];
Qlik Sense 表格示出来自加载脚本中 Num 函数的不同使用的结果。表格的第四列包含不正确的格式使用,例如用途。
No formatting | 0 | #,##0 | # ###,00 | # ###,00 , ',' , ' ' | #,###.00 , '.' , ',' | $#,###.00 |
---|
-59.18 | -59 | -59 | -59###,00 | -59,18 | -59.18 | $-59,18 |
15.75 | 16 | 16 | 16###,00 | 15,75 | 15.75 | $15,75 |
1251 | 1251 | 1,251 | 1251###,00 | 1 251,00 | 1,251.00 | $1,251.00 |
3177.4 | 3177 | 3,177 | 3177###,00 | 3 177,40 | 3,177.40 | $3,177.40 |
5356.31 | 5356 | 5,356 | 5356###,00 | 5 356,31 | 5,356.31 | $5,356.31 |
12423.56 | 12424 | 12,424 | 12424###,00 | 12 423,56 | 12,423.56 | $12,423.56 |
21484.21 | 21484 | 21,484 | 21484###,00 | 21 484,21 | 21,484.21 | $21,484.21 |