<分区>
请告诉我这两种方法之间的区别。提前致谢。
标签 java string bigdecimal
<分区>
请告诉我这两种方法之间的区别。提前致谢。
最佳答案
Java toString() 方法:
If you want to represent any object as a string, toString() method comes into existence.The toString() method returns the string representation of the object.
示例:
Student s1 = new Student(101,"Raj","lucknow");
Student s2 = new Student(102,"Vijay","ghaziabad");
System.out.println(s1);//compiler writes here s1.toString()
System.out.println(s2);//compiler writes here s2.toString()
//Output : 101 Raj lucknow
102 Vijay ghaziabad
Java toPlainString() 方法:
The java.math.BigDecimal.toPlainString() returns a string representation of this BigDecimal without an exponent field.
示例:
MathContext mc = new MathContext(3); // 3 precision
BigDecimal bigDecimal = new BigDecimal("1234E+4", mc);
// Assign the plain string value of bigDecimal to s
String plainString = bigDecimal.toPlainString();
String str = "Plain string value of " + bigDecimal + " is " + plainString;
// print s value
System.out.println( str );
//Output : Plain string value of 1.23E+7 is 12300000
关于java - Java 中的 toPlainString() 和 toString() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33563946/