此函数将真实的数字转换为字符串,您可以在其中指定小数点两侧可见的位数。
total参数是小数点左边的位数,如果这比您的值允许的要高,则插入空格以填充剩余的位数。dec参数是小数点右边的位数,如果这比您的数字中的小数点位数要多,则插入零以保持给定的位数。
默认格式是左边没有多余的空格,右边只有两位小数,例如"265.73"。
string_format(val, total, dec);
参数 | 类型 | 描述 |
---|---|---|
val | Real | 要转换为字符串的真实的数字。 |
total | Real | 要显示的主数字的位数(小数点左边)。将插入空格以匹配此位数。 |
dec | Real | 要包含的小数位数(小数点右侧)。将插入零以与此匹配。 |
str1 = string_format(1234, 8, 0);
str2 = string_format(pi, 1, 10);
str3 = string_format(pi, 5, 5);
This will set str1 to " 1234", str2 to "3.1415926536" and str3 to " 3.14159".