toString or not toString

Marco Leise Marco.Leise at gmx.de
Wed Aug 31 08:38:31 PDT 2011


Am 31.08.2011, 11:13 Uhr, schrieb Jonathan M Davis <jmdavisProg at gmx.com>:

> Java has a toString which doesn't take any arguments, and it works fine.

Let's look at Java again. They have BigDecimal, so how does that work?
First of all they added convenience functions akin to "toString()" to  
BigDecimal: "toEngineeringString()" and "toPlainString()".
Their number formatting class has a method with a long list of cases that  
distinguishes between the different Number classes including wrapper  
objects around primitive types and BigDecimal. So they practically have a  
sealed list of numerical types that are specially formatted, while for the  
rest "doubleValue()" is called.


More information about the Digitalmars-d mailing list