I am trying to format a decimal number such as 0.0567
but forgot how to do formatting in C#.
I tried the old C format escape sequence "\8.3f" the old C style but does
not work.
example: dMyNumber.tostring("\8.3f");
Can some one refresh how to do this?
Thanks 9 2289
NeilGott wrote:
I am trying to format a decimal number such as 0.0567
but forgot how to do formatting in C#.
I tried the old C format escape sequence "\8.3f" the old C style but does
not work.
example: dMyNumber.tostring("\8.3f");
Can some one refresh how to do this?
Thanks
double doubleNumber;
doubleNumber = 18934.1879;
Console.WriteLine(doubleNumber.ToString("F",
CultureInfo.InvariantCulture));
"NeilGott" <Ne******@discussions.microsoft.comwrote in message
news:6E**********************************@microsof t.com...
>I am trying to format a decimal number such as 0.0567
but forgot how to do formatting in C#.
For future reference: http://msdn.microsoft.com/en-us/library/427bttx3.aspx
Thanks for your reponse. So how come the old C style formats do not work?
Do you know how I can specify precision, say I want 5 decimal places etc?
"Ashutosh Bhawasinka" wrote:
NeilGott wrote:
I am trying to format a decimal number such as 0.0567
but forgot how to do formatting in C#.
I tried the old C format escape sequence "\8.3f" the old C style but does
not work.
example: dMyNumber.tostring("\8.3f");
Can some one refresh how to do this?
Thanks
double doubleNumber;
doubleNumber = 18934.1879;
Console.WriteLine(doubleNumber.ToString("F",
CultureInfo.InvariantCulture));
Thanks for the link Jeff. So the old escape foramt type in Standard C,
i.e %8.5f or "%6.3d" do not work with ToString().
I seem to recall being able to do this in Csharpe.
Would use a few examples, here is what I use to do in old c style:
fprintf(' Mean Of Cumulative Weighted Returns %8.3f\n', MeanCumulative)
Hope you can give me a few examples, so rusty on formatting!
Thanks.
"Jeff Johnson" wrote:
"NeilGott" <Ne******@discussions.microsoft.comwrote in message
news:6E**********************************@microsof t.com...
I am trying to format a decimal number such as 0.0567
but forgot how to do formatting in C#.
For future reference: http://msdn.microsoft.com/en-us/library/427bttx3.aspx
NeilGott wrote:
So how come the old C style formats do not work?
For much the same reason there's no printf(): apart from the syntactical
resemblance, C# and C are completely different languages. On the other hand,
the same formatting strings work in C# and VB.NET, because they're both .NET
languages and they share the same framework library.
--
J.
Jeroen:
I tried the old formating strings (i.e dMNumber.tostring("%8.3f")
and it does not work. Seems the 83 above gets appedned to the number.
So old style doesn't seem to work with .NET tostring() function.
Perhaps i am wrong?
"Jeroen Mostert" wrote:
NeilGott wrote:
So how come the old C style formats do not work?
For much the same reason there's no printf(): apart from the syntactical
resemblance, C# and C are completely different languages. On the other hand,
the same formatting strings work in C# and VB.NET, because they're both .NET
languages and they share the same framework library.
--
J.
NeilGott wrote:
I am trying to format a decimal number such as 0.0567
but forgot how to do formatting in C#.
I tried the old C format escape sequence "\8.3f" the old C style but does
not work.
example: dMyNumber.tostring("\8.3f");
Can some one refresh how to do this?
Thanks
I think that the composite formatting string "f3,8" is what you are
looking for:
string formatted = String.Format("{0:f3,8}", theNumber);
"f3" formats the number rounded to three decimal places, and ",8" right
aligns it to the length of eight characters.
--
Göran Andersson
_____ http://www.guffa.com
NeilGott wrote:
I tried the old formating strings (i.e dMNumber.tostring("%8.3f")
and it does not work. Seems the 83 above gets appedned to the number.
So old style doesn't seem to work with .NET tostring() function.
Perhaps i am wrong?
No, you're not. Where did I ever say this should work? What I said was that
C# and VB.NET (and all the other .NET languages) support the same formatting
strings, which are explicitly *not* C formatting strings.
--
J.
Thanks for your response.
I must be doing something wrong trying your suggestion,
it prints f38 when I tried this:
txtbResults.AppendText("New Ratio Simulated: " +
String.Format("{0:f3,8}",dSimulatedRatioData))+ Environment.NewLine);
documentation online just does not show the old K&R C style formating
from an old K&R C programmer.
Anyone know how to apply this correcty?
"Göran Andersson" wrote:
NeilGott wrote:
I am trying to format a decimal number such as 0.0567
but forgot how to do formatting in C#.
I tried the old C format escape sequence "\8.3f" the old C style but does
not work.
example: dMyNumber.tostring("\8.3f");
Can some one refresh how to do this?
Thanks
I think that the composite formatting string "f3,8" is what you are
looking for:
string formatted = String.Format("{0:f3,8}", theNumber);
"f3" formats the number rounded to three decimal places, and ",8" right
aligns it to the length of eight characters.
--
Göran Andersson
_____ http://www.guffa.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: phmyhn |
last post by:
I have two web pages, one is viewlarger.aspx, another one is
shoppingcart.aspx. On the viewlarger.aspx, when clicking "add to cart"
image button, the sub appends the id (passed from another page...
|
by: John Chorlton |
last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid...
|
by: Robin Tucker |
last post by:
My database has a column for numeric data items. How can I use
this number in the "format" command, such that for, say precision 2, I get
numbers like 2011.01 or 2387.00 and for 4 I would get...
|
by: Al Reid |
last post by:
First, I'm using vb2005. I have a string that is read from a barcode reader into a TextBox. The string is 6 characters long and
represents a date (mmddyy). I want to display it to the user in a...
|
by: Fei Liu |
last post by:
In Accellerated C++, the author recommends that in a header file one should
not declare
using std::string, using std::vector etc instead one should directly specify
the namespace specifier in...
|
by: Pieter Coucke |
last post by:
Hi,
When a user types a non numeric-value in a numeric column in a DataGridView,
and he tries to leave the cell, he gets this "Input string was not in a
correct format."-exception.
Is there a...
|
by: Jen |
last post by:
One user of my application is experiencing an exception "input string not in
correct format". But it makes no sense where it is occurring. It is
occurring when a string from a textbox ("172") is...
|
by: shill57957 |
last post by:
I have a query:
SELECT .AH_TICKNO, Format((.AH_AMOUNT-.AH_TRNAMT)/.AH_AMOUNT,"Percent") AS DIF INTO
FROM ;
I dont want to format as a percent, I want it to go into the table
with 4 decimal...
|
by: clarencemo |
last post by:
Hello,
I currently have a split db and I keep getting this error after about a day's worth of use. Once I've repaired it, I have created a clean db, imported the tables from a previous backup and...
|
by: vikas251074 |
last post by:
I am getting error above in following code since few days giving tension day and night.
How can I solve this? I am facing since Oct.25. in line no. 362
After doing a lot of homework, I am...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |