formatting output (CString .Format...)
-
Hello, INTRODUCTION: I need to show four real numbers in a CStatic. I've linked that CStatic to a CString var (let's call it statstring). QUESTION: I'm using this syntax:
statstring.Format(" AB: %4.4lfmm - CD: %4.4lfmm - EF: %4.4lfmm - GH: %4.4lfmm",CAB,CCD,CEF,CGH);
I'm trying to show something like:
"AB: 0000.0000 - CD: 0000.0000 - EF: 0000.0000 - GH: 0000.0000"
but I get:"AB: 0.0000 - CD: 0.0000 - EF: 0.0000 - GH: 0.0000"
and the problem (is merely anaesthetic problem) is that each time that the numbers change they change their position too. How should I modify the format string in order to get it? As always thank you in advance. -
Hello, INTRODUCTION: I need to show four real numbers in a CStatic. I've linked that CStatic to a CString var (let's call it statstring). QUESTION: I'm using this syntax:
statstring.Format(" AB: %4.4lfmm - CD: %4.4lfmm - EF: %4.4lfmm - GH: %4.4lfmm",CAB,CCD,CEF,CGH);
I'm trying to show something like:
"AB: 0000.0000 - CD: 0000.0000 - EF: 0000.0000 - GH: 0000.0000"
but I get:"AB: 0.0000 - CD: 0.0000 - EF: 0.0000 - GH: 0.0000"
and the problem (is merely anaesthetic problem) is that each time that the numbers change they change their position too. How should I modify the format string in order to get it? As always thank you in advance.From the top of my hat... Add some zeroes: statstring.Format(" AB: %04.4lfmm - CD: %04.4lfmm - EF: %04.4lfmm - GH: %04.4lfmm",CAB,CCD,CEF,CGH); I didn't try whether it works. ------------------------------------------ Experience is the name every one gives to their mistakes. -- Oscar Wilde Experience is one thing you can't get for nothing. -- Oscar Wilde
-
From the top of my hat... Add some zeroes: statstring.Format(" AB: %04.4lfmm - CD: %04.4lfmm - EF: %04.4lfmm - GH: %04.4lfmm",CAB,CCD,CEF,CGH); I didn't try whether it works. ------------------------------------------ Experience is the name every one gives to their mistakes. -- Oscar Wilde Experience is one thing you can't get for nothing. -- Oscar Wilde
-
Ok, try %09.4 That one works, I tested it. 0 is flag telling to fill the minimum length with zeroes, 9 is the length, 4 is the precision (in case someone wonders about that). ------------------------------------------ Experience is the name every one gives to their mistakes. -- Oscar Wilde Experience is one thing you can't get for nothing. -- Oscar Wilde
-
Hello, INTRODUCTION: I need to show four real numbers in a CStatic. I've linked that CStatic to a CString var (let's call it statstring). QUESTION: I'm using this syntax:
statstring.Format(" AB: %4.4lfmm - CD: %4.4lfmm - EF: %4.4lfmm - GH: %4.4lfmm",CAB,CCD,CEF,CGH);
I'm trying to show something like:
"AB: 0000.0000 - CD: 0000.0000 - EF: 0000.0000 - GH: 0000.0000"
but I get:"AB: 0.0000 - CD: 0.0000 - EF: 0.0000 - GH: 0.0000"
and the problem (is merely anaesthetic problem) is that each time that the numbers change they change their position too. How should I modify the format string in order to get it? As always thank you in advance.statstring.Format(" AB: %09.4lfmm - CD: %09.4lfmm - EF: %09.4lfmm - GH: %09.4lfmm",CAB,CCD,CEF,CGH);
0 indicates to fill up with zeros before the comma, 9 gives the minimal length of output (4 before the comma + comma + 4 after comma), 4 gives the numbers after the comma -- karl -
Ok, try %09.4 That one works, I tested it. 0 is flag telling to fill the minimum length with zeroes, 9 is the length, 4 is the precision (in case someone wonders about that). ------------------------------------------ Experience is the name every one gives to their mistakes. -- Oscar Wilde Experience is one thing you can't get for nothing. -- Oscar Wilde
-
statstring.Format(" AB: %09.4lfmm - CD: %09.4lfmm - EF: %09.4lfmm - GH: %09.4lfmm",CAB,CCD,CEF,CGH);
0 indicates to fill up with zeros before the comma, 9 gives the minimal length of output (4 before the comma + comma + 4 after comma), 4 gives the numbers after the comma -- karl