Reply to topic  [ 4 posts ] 
How do I stop getting scientific notation and get decimal? 
Author Message
Yorick Padawan

Joined: Tue Jun 07, 2011 1:46 pm
Posts: 32
Location: UNH
Post How do I stop getting scientific notation and get decimal?
How do I stop getting scientific notation and get decimal?

Quote:
> a = [450000000];
> a
[450000000]
> a = [450000000, 0.99];
> a
[4.5e+08,0.99]

I have a function where I'd like to return an X and Y, my X is 6 digits while my Y is 7 digits. I can return Y by itself and it will not return in scientific notation, but if I return both in an array, it will show Y in scientific notation and will show X normally. I looked through the manual and couldn't find a way to do this.

Ronak


Wed Jul 27, 2011 11:28 am
Profile
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Post Re: How do I stop getting scientific notation and get decima
The write command lets you format numerical output.

Code:
> write, format="%.2f\n", [450000000, 0.99]
450000000.00
0.99


You can also change the default behavior for output using "print_format".

Code:
> print_format, double="%.3f"
> [450000000, 0.99]
[450000000.000, 0.990]


Last edited by dnagle on Mon Aug 01, 2011 6:14 am, edited 1 time in total.



Wed Jul 27, 2011 1:08 pm
Profile
Yorick Padawan

Joined: Tue Jun 07, 2011 1:46 pm
Posts: 32
Location: UNH
Post Re: How do I stop getting scientific notation and get decima
Yes! Exactly what I wanted. I didn't know there was a global setting you could call to always see decimal. Very nice.

Thanks,


Thu Jul 28, 2011 11:06 am
Profile
Yorick Master

Joined: Mon Nov 22, 2004 9:43 am
Posts: 354
Location: Livermore, CA, USA
Post Re: How do I stop getting scientific notation and get decima
If you want detailed control over formatting, use the write function. The print function is for interactive use (read debugging). It uses ANSI C %g format, which is what you want for rough and ready output. You certainly do not want to set the double format for print to %.3f -- the ANSI C %f format is extremely dangerous, because there is not way to put an upper bound on the number of characters it might need to display. You can easily run out of buffer space if you print big numbers (try 1e100), which may produce a SIGSEGV from buffer overflow, and probably damages that copy of yorick. A safer choice would be %#g (see help,write to find out that the # ensures a decimal point for f and g format, or read the man page for the libc printf function). I prefer %g. As I said, if you want to get fussy about the format, you need to use the ANSI C formatting available with the write and swrite functions. Don't forget the new totxt function as well, which has a simpler interface specialized for numbers.


Sat Jul 30, 2011 6:48 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.