首页 > 文档 > nfs()数字格式化为字符串函数
2017
07-21

nfs()数字格式化为字符串函数

Name

nfs()数字格式化为字符串函数

   

Examples

int a=200, b=-40, c=90;

String sa = nfs(a, 10);

println(sa); // Prints ” 0000000200″

String sb = nfs(b, 5);

println(sb); // Prints “-00040”

String sc = nfs(c, 3);

println(sc); // Prints ” 090″

 

float d = -200.94, e = 40.2, f = -9.012;

String sd = nfs(d, 10, 4);

println(sd); // Prints “-0000000200.9400”

String se = nfs(e, 5, 3);

println(se); // Prints ” 00040.200″

String sf = nfs(f, 3, 5);

println(sf); // Prints “-009.01200”

Description

Utility function for formatting numbers into strings. Similar to nf(), but leaves a blank space in front of positive numbers so they align with negative numbers in spite of the minus symbol. There are two versions: one for formatting floats, and one for formatting ints. The values for the digitsleft, and right parameters should always be positive integers.

用于将数字格式化为字符串的实用程序函数。类似于 nf (), 但在正数前留下一个空格, 使它们与负数对齐, 尽管有负号。有两个版本: 一个用于格式化浮动, 一个用于格式化整数。数字、左和右参数的值应始终为正整数。

Syntax

nfs(num, digits)

nfs(nums, digits)

nfs(nums, left, right)

nfs(num, left, right)

Parameters

num

float, or int: the number to format

要转换的数字

digits

int: number of digits to pad with zeroes

用零填充的位数

nums

float[], or int[]: the numbers to format

要转换的数字

left

int: the number of digits to the left of the decimal point小数点左边的位数

right

int: the number of digits to the right of the decimal point小数点右边的位数

Returns

String or String[]

Related

nf()
nfp()
nfc()



最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。