Alright, so I've searched the book I'm learning from, as well as the internet, and can't seem to find an answer to this...so I am turning to /prog/ as my last resort:
in the conversion specification %-6.2g, what does the .2 mean?
I know that the -6 means that there are a maximum of 6 characters shown, and that it is left justified, but the book doesn't mention what the number following a decimal means.
Help is greatly appreciated, thanks in advance
It means C/C++ sucks and you should implement your own DSL like "x=$(format x precission=2)".
Name:
Anonymous2011-02-18 17:48
>>4
Okay, could you help me understand how %-6.2g effects .0000009979?
By that I mean what steps are made during printf? I'll make a random guess to show what kind of answer I am looking for:
"First, it takes the value of the second 0 (.00), and then prints it's value in exponential form, which is rounded to 1. So the result is 1e-06, but since we have %-6, we must show 6 characters, so it displays as 1e-06(space)"
I'm just a little unclear on what the # of decimal places mean :S
Name:
Anonymous2011-02-18 17:51
>>5
Link to the manual then? I tried searching online, and it's not in the book, that means I obviously couldn't find the answer, which isn't surprising because if I tried to search "%g conversion specification", it just gave me the same unclear info as the book, and if I tried to make it more specific I got no real results at all.
The precision
An optional precision, in the form of a period ('.') followed by an
optional decimal digit string. Instead of a decimal digit string one
may write "*" or "*m$" (for some decimal integer m) to specify that the
precision is given in the next argument, or in the m-th argument,
respectively, which must be of type int. If the precision is given as
just '.', or the precision is negative, the precision is taken to be
zero. This gives the minimum number of digits to appear for d, i, o,
u, x, and X conversions, the number of digits to appear after the radix
character for a, A, e, E, f, and F conversions, the maximum number of
significant digits for g and G conversions, or the maximum number of
characters to be printed from a string for s and S conversions.
>>10
That doesn't really help though...I need it in simple terms lol, let's have one more go at this:
0.0000009979
if it has two decimal places, does that mean it is going to give the exponential value of the second 0 that comes after the decimal?
0.0(0) <-- is it gonna return what the value of that bracketed zero is, if not, which zero would it be giving the value of...or am I completely wrong here?
>>12
Serious question, are you mentally challenged and/or French?
Name:
Anonymous2011-02-18 19:03
Oh wow I feel stupid...decimal places = significant digits, am I right?
So am I right in saying that instead of it being .97e-7 (.97 being the first two significant digits), it rounds to 1e-6?
>>13
Hey, I'm French. Are you insulting me?! I don't understand you!!
Name:
Anonymous2011-02-18 19:16
>>13
Neither. Also, nevermind 14 because decimal places is not the same as significant digits, so that just made me feel even more stupid...I just happen to be having trouble figuring out WHAT having 2 decimal places means exactly. I know the input, and I know the output, and I know what the %-6 means...I don't see why you guys can't just give me a simple answer as to what it means when it says the output will have 2 decimal places, mainly because 1e-6 doesn't SHOW any decimal places.
Name:
Anonymous2011-02-18 19:19
Would be great if one of you could just show me in the same way as when a teacher writes something on a board, I need a visual.
Name:
Anonymous2011-02-18 20:17
nevermind I figured it out...was having a major brainfart.