C# forum for web developers

String.Format newb

Dec 22, 2010 5:45 pm
Mp

given
Excel.Range rng1 = _xlWorkSheet.get_Range(rangeName, Type.Missing);
string cash = String.Format("{0: ###,###.##}",
rng1.Value2);

I get the string "123,546"
but it should be "123,546.00"

what am i doing wrong?
thanks
mark

Dec 22, 2010 5:50 pm
Mp
Re: string.Format newb


"mp" <nospam@Thanks.com> wrote in message
news:ietdf7$f8d$1@news.eternal-september.org...
> given
> Excel.Range rng1 = _xlWorkSheet.get_Range(rangeName, Type.Missing);
> string cash = String.Format("{0: ###,###.##}",
> rng1.Value2);
>
> I get the string "123,546"
> but it should be "123,546.00"
>
> what am i doing wrong?
> thanks
> mark
>


nevermind, got it...don't understand why it works but i tried this
string cash = String.Format("{0: ###,###.00}", rng1.Value2);
and it works even if the last two digits aren't 0.
thanks
mark





Dec 22, 2010 7:07 pm
Jeff Johnson
Re: string.Format newb

"mp" <nospam@Thanks.com> wrote in message
news:ietdf7$f8d$1@news.eternal-september.org...

> given
> Excel.Range rng1 = _xlWorkSheet.get_Range(rangeName, Type.Missing);
> string cash = String.Format("{0: ###,###.##}",
> rng1.Value2);
>
> I get the string "123,546"
> but it should be "123,546.00"
>
> what am i doing wrong?

Forgetting even your basic VB training, that's what. Using 0 as a
placeholder instead of # FORCES a digit there, even if it's 0. Format$()
uses the same rules; I'm surprised you've never run across it before. Tsk
tsk, Mark!




Dec 22, 2010 8:48 pm
Mp
Re: string.Format newb


"Jeff Johnson" <i.get@enough.spam> wrote in message
news:ieti9d$plf$1@news.eternal-september.org...
> "mp" <nospam@Thanks.com> wrote in message
> news:ietdf7$f8d$1@news.eternal-september.org...
>
>> given
>> Excel.Range rng1 = _xlWorkSheet.get_Range(rangeName, Type.Missing);
>> string cash = String.Format("{0: ###,###.##}",
>> rng1.Value2);
>>
>> I get the string "123,546"
>> but it should be "123,546.00"
>>
>> what am i doing wrong?
>
> Forgetting even your basic VB training, that's what. Using 0 as a
> placeholder instead of # FORCES a digit there, even if it's 0. Format$()
> uses the same rules; I'm surprised you've never run across it before. Tsk
> tsk, Mark!

yeah i'm even more ashamed of me than you are
:-)
i've probably seen it in the dim past but dont' recall ever having to use
it.
it did eventually surface in my brain but took a while
:-)
you're awfully gentle in your upbrading(compared to what i deserve)...must
be in the christmas spirit






Previous Thread: App.config ??
Next Thread: Unable to save byte[] to database

Related Forum Topics
How to make a fancy format
Hello!

Here is the code that update the listBox but there is a small problem. When
I have different number of item in the foodList will the position for the
column title not be lined up the the data. How do I best solve this lined up
between the column title and the data for the...
Image is not getting save as RTF format
Dear friends,

In my project hrn dll is using for saving html into RTF format.

but html which contains images is not getting save in RTF format.

What is the reason

Please help me

Thanks in Advance


Table Format to Hold Data
Hello,

I need to store some strings in different languages as follows:

"Hello", "en" ; "Olá", "pt" ; "Bounjour", "fr"

"Goodbye", "en" ; "Adeus", "pt" ; "Adieu", "fr"

Then I would have two methods:

String Translate(String value, String fromLanguage,...
Equals(String, String, StringComparison) ?
While I was browsing at MSDN, at http://msdn.microsoft.com/en-us/library/bb546166.aspx
, I happen to see some community comments:

<quote>
In the above Linq query. Better performance would be achieved by using
string.Equals() with a StringComparison enumerable as below.

var matchQuery =...
Using current date and time format as serial number tia sal22
Greetings All

I would like to use the current date and time as a serial number in csharp what command or tutorial if there is one should I use?
example: of what I'm trying to produce.

12 03 2010 09 49 33.416
This would represent december 03 2010, 09:49:33.416 am Also how would I create...