⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e324. formatting a message containing a number.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
Object[] params = new Object[]{new Integer(123), new Integer(1234)};
    String msg = MessageFormat.format("There are {0} a''s and {1} b''s", params);
    // There are 123 a's and 1,234 b's
    
    msg = MessageFormat.format("There are {0,number} a''s and {1,number} b''s", params);
    // There are 123 a's and 1,234 b's
    
    // Use a custom format; see e311 Formatting a Number Using a Custom Format
    msg = MessageFormat.format("There are {0,number,#} a''s and {1,number,#} b''s", params);
    // There are 123 a's and 1234 b's
    
    // Floating point numbers
    params = new Object[]{new Double(123.45), new Double(1234.56)};
    msg = MessageFormat.format("There are {0,number,#.#} a''s and {1,number,#.#} b''s", params);
    // There are 123.4 a's and 1234.6 b's
    
    // Currency
    msg = MessageFormat.format("There are {0,number,currency} a''s and {1,number,currency} b''s", params);
    // There are $123.00 a's and $1,234.00 b's
    
    // Percent
    msg = MessageFormat.format("There are {0,number,percent} a''s and {1,number,percent} b''s", params);
    // There are 12,345% a's and 123,456% b's

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -