فونكشن فورمات() فايرمات فايرمات
The format() function formats a value.
syntax
n = String.format(format, value)
component | description |
---|---|
n | The string returned by the function. |
format | Specify how to format the value. |
value | The value to be formatted. |
format consists of three parts: %width.precision type
width - optional. Specifies the minimum number of output characters.
precision - optional. Sets the accuracy of the output value. The following values can be used:
- d - minimum number of output digits. Default is 1.
- f - number of decimal places. Default is 6.
- s - maximum number of output characters. Defaults to output all characters.
type - required. Determines how the formatted value is interpreted. The following values can be used:
- d - integer
- f - floating point number
- s - string
example
var b = String.format("%4.3d", 32); var d = String.format("%3f", 10.1234); var e = String.format("%2.2f", 2.3)
result
b = " 032" d = "10.123" e = "2.30"