Java中的printf风格格式化详解
1. 解析数值示例
首先来看一个解析数值的示例代码:
// Create a ParsePosition object to specify the first digit of number
// in the string. It is 4 in "XY4,123.983" with the index 2.
ParsePosition pos = new ParsePosition(2);
Number numberObject = formatter.parse(str, pos);
double value = numberObject.doubleValue();
System.out.println("Parsed Value is " + value);
运行上述代码,输出结果为:
Parsed Value is 4123.983
2. printf风格格式化概述
在Java中, java.util.Formatter 类支持类似C语言中 printf() 函数的格式化方式。下面是一个简单的示例代码:
// PrintfTest.java
package com.jdojo.format;
import java.util.Date;
public class PrintfTest {
public static
超级会员免费看
订阅专栏 解锁全文
1766

被折叠的 条评论
为什么被折叠?



