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

📄 e312. formatting and parsing a number for a locale.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
A formatted number consists of locale-specific symbols such as the decimal point. For example, a Canadian decimal point is a dot while a German decimal point is a comma. This example demonstrates how to format a number for a particular locale. 
    // Format for CANADA locale
    Locale locale = Locale.CANADA;
    String string = NumberFormat.getNumberInstance(locale).format(-1234.56);  // -1,234.56
    
    // Format for GERMAN locale
    locale = Locale.GERMAN;
    string = NumberFormat.getNumberInstance(locale).format(-1234.56);   // -1.234,56
    
    // Format for the default locale
    string = NumberFormat.getNumberInstance().format(-1234.56);
    
    
    // Parse a GERMAN number
    try {
        Number number = NumberFormat.getNumberInstance(locale.GERMAN).parse("-1.234,56");
        if (number instanceof Long) {
            // Long value
        } else {
            // Double value
        }
    } catch (ParseException e) {
    }

⌨️ 快捷键说明

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