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.tostr ing("\8.3f");
Can some one refresh how to do this?
Thanks 9 2305
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.tostr ing("\8.3f");
Can some one refresh how to do this?
Thanks
double doubleNumber;
doubleNumber = 18934.1879;
Console.WriteLi ne(doubleNumber .ToString("F",
CultureInfo.Inv ariantCulture)) ;
"NeilGott" <Ne******@discu ssions.microsof t.comwrote in message
news:6E******** *************** ***********@mic rosoft.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.tostr ing("\8.3f");
Can some one refresh how to do this?
Thanks
double doubleNumber;
doubleNumber = 18934.1879;
Console.WriteLi ne(doubleNumber .ToString("F",
CultureInfo.Inv ariantCulture)) ;
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******@discu ssions.microsof t.comwrote in message
news:6E******** *************** ***********@mic rosoft.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.tostri ng("%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.tostr ing("\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.tostri ng("%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.App endText("New Ratio Simulated: " +
String.Format(" {0:f3,8}",dSimu latedRatioData) )+ Environment.New Line);
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.tostr ing("\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 from a
hyperlink column) into a session. the code is as following:
Private Sub ibtAddtoCart_Click(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs) Handles
ibtAddtoCart.Click
idStr = Session("ids")
pid =...
|
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 creating many public properties on the form to do the same thing. At first I tried returning a DataViewRow. This worked fine until I reached the phone field on the parent table and the code
Child form
public DataRowView SelectedAddres
ge
...
|
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 2011.0100 or
2387.0000?
(simple question I know!)
|
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 date format of "mm/dd/yy" For example the barcode contains
"112303" and I want to format it to display "11/23/03"
If I use the microsoft.visualbasic.strings.format with a format string of "##/##/##" or "00/00/00" I get the format string in the...
|
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 code.
for example, this is bad practice:
header.h
#include <string>
using std::string;
| |
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 (nice) way to get rid of this exception? And just put a "0" in
the place? Or somehow trigger this single exception (does exceptions have a
unique type-number?) and do some appropriate actions?
|
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 being convert to an Int16
(using Convert.ToInt16). How can that be? There are other text boxes that
are used in the identical fashion and they don't generate the exception.
All there are many other machines running my application that don't...
|
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 places, for example .0397
how do I use the format statement and get this result?
|
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 everything works with no issues, until the next day when it gets corrupted again. I thought at first it was a bad form. so I rebuilt it.
Can u look at the code on this form?
What this form does is it inserts data from end-users (who have the...
|
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 surrendered to you.
<%@ Language=VBScript%>
<%Option Explicit%>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |