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

dnagle

Yorick Master

Joined: Wed Jun 01, 2005 11:34 amPosts: 112

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.000.99

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

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.

Who is online

Users browsing this forum: No registered users and 1 guest

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