[vwnc] Something like printf?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[vwnc] Something like printf?

David Finlayson-4
I am looking for something like printf's for streams. I need to
control the precision of numbers being output to a text file.

Thanks,

David
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Something like printf?

Andres Valloud-6
You may want to take a look at the method below.  IIRC, it has been
added for 7.7, but should work on 7.6 and earlier.

Number>>printFormat: aFormatPattern
        "Shorthand for printing numbers with a given format. See
NumberPrintPolicy's comment for format description."
        "100 printFormat: '#.0'"
        "Double pi printFormat: '000.####'"
       
        | stream |
        stream := (String new: aFormatPattern size) writeStream.
        self printOn: stream format: aFormatPattern.
        ^stream contents

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On
Behalf Of David Finlayson
Sent: Wednesday, May 13, 2009 2:32 PM
To: VW NC
Subject: [vwnc] Something like printf?

I am looking for something like printf's for streams. I need to control
the precision of numbers being output to a text file.

Thanks,

David
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Something like printf?

Eliot Miranda-2
In reply to this post by David Finlayson-4


On Wed, May 13, 2009 at 2:31 PM, David Finlayson <[hidden email]> wrote:
I am looking for something like printf's for streams. I need to
control the precision of numbers being output to a text file.



You could start from Squeak's facilities such as printPaddedWith:to:, e.g.
      "Answer the string containing the ASCII representation of the receiver 
padded on the left with aCharacter to be at least on aNumber 
integerPart characters and padded the right with aCharacter to be at 
least anInteger fractionPart characters."

    ((1000 / 3) roundTo: 0.001) printPaddedWith: $_ to: 4.2 '_333.333_'

Buggy but fixable.
 
Thanks,

David
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Something like printf?

Joachim Geidel
In reply to this post by David Finlayson-4
Re: [vwnc] Something like printf? The package “JNIPort StandardLibInterface” in the Cincom public repository contains extensions to String for calling snprintf(), supporting the complete set of printf formats. You should load the bundle “JNIPort Prerequisites” to get everything which is needed. The license allows you to extract what you need into your own – probably much smaller – package.

The StandardLibInterface interface lets you do things like
    '[%*.*f][%*.*e]' sprintfWithArguments: #(12 2 3.141592653 12 2 3.141592653)  ==>  '[        3.14][    3.14e+00]'

HTH,
Joachim Geidel

Am 13.05.09 23:31 schrieb David Finlayson:

I am looking for something like printf's for streams. I need to
control the precision of numbers being output to a text file.

Thanks,

David
_______________________________________________
vwnc mailing list
vwnc@...
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Something like printf?

Georg Heeg
In reply to this post by David Finlayson-4
ObjectStudio has full support of printf

Georg

Georg Heeg eK, Dortmund und Köthen, HR Dortmund A 12812
Tel. +49-3496-214328, Fax +49-3496-214712

> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]] Im Auftrag
> von David Finlayson
> Gesendet: Mittwoch, 13. Mai 2009 23:32
> An: VW NC
> Betreff: [vwnc] Something like printf?
>
> I am looking for something like printf's for streams. I need to
> control the precision of numbers being output to a text file.
>
> Thanks,
>
> David
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc