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

nfp()数字格式化字符串函数

Name

nfp()数字格式化字符串函数

   

Examples

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

String sa = nfp(a, 10);

println(sa); // Prints “+0000000200”

String sb = nfp(b, 5);

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

String sc = nfp(c, 3);

println(sc); // Prints “+090”

 

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

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

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

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

println(se); // Prints “+00040.200”

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

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

Description

Utility function for formatting numbers into strings. Similar to nf() but puts a “+” in front of positive numbers and a “-” in front of negative numbers. 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

nfp(num, digits)

nfp(nums, digits)

nfp(nums, left, right)

nfp(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()
nfs()
nfc()



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

留下一个回复

你的email不会被公开。