Search |
||
How to format a string?Posted by malenkov on January 26, 2009 at 6:00 AM PST
Sometimes users need to prepare their data for output. Java provides support for layout justification and alignment, common formats for numeric, string, and date/time data, and locale-specific output. However, the JavaFX language reference just briefly mentions this functionality. JavaFX Script enables developers to embed expressions into the string using the curly braces. It is very useful because the language does not support the Java: String str = "prefix" + object + "postfix";
JavaFX: var str = "prefix{object}postfix";
If users need to format the object, they could use the Java: String str = String.format("cost: %.2f $", number);
JavaFX: var str = "cost: {%.2f number} $";
The format specifiers for general, character, and numeric types have the following syntax: The detailed information about the format specifiers is available here. Note that the format specifiers in JavaFX do not use the argument index, because these specifiers are already placed before the argument. »
Related Topics >>
Programming Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|