[Glass] Is there a way to print a Float with all decimals but without exponential notation?

Mariano Martinez Peck marianopeck at gmail.com
Tue Mar 4 12:12:15 PST 2014

On Tue, Mar 4, 2014 at 4:39 PM, Martin McClure <
martin.mcclure at gemtalksystems.com> wrote:

>> Hi Martin,
>> Yes, that looks a bit clunky and probably slow? I am writing reports
>> where I print lots of floats, so this may be important.
>> Also, yes, my numbers can be negative and even between 0 and 1.0. Also,
>> not only Float but SmallDouble as well....
>> Wish there could be a simple method (primitive) to print all type of
>> 64-bits floats without the exponential notion...
>> For the moment I guess I will stay with the exponential :(
> Hi Mariano,
> Clunky it definitely is. Though the *real* algorithm would be a lot more
> complicated.
> But how slow is slow? How many is "lots" and how often do you need to
> print them? When it comes to performance, assumptions are very risky. I
> recommend trying it and testing what the performance is, rather than
> assuming it will be too slow. You can probably do that kind of test in half
> an hour or so.
Yes, probably I am exaggerating ;)

> SmallDouble and Float should be completely polymorphic (at least plenty
> polymorphic for this job), so you shouldn't have to worry about the
> difference. The handling of negative and 0 - 1 won't add much complexity.

OK...so let's try implementing that method. Is it as simple as this or I am
missing something?

Float >> asStringWithAllDecimalsAndNoExponentialNotation
| truncatedStringSize |
truncatedStringSize := self truncated printString size.
(self >= 1.0)
ifTrue: [ ^ self asStringUsingFormat: {0. 17 - truncatedStringSize. false} ]
 ifFalse: [ ^ self asStringUsingFormat: {0. 18 - truncatedStringSize.
false} ]


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20140304/2166b0c6/attachment.html>

More information about the Glass mailing list