Discussion:
Problem with Double::ToString(__,__)
(too old to reply)
Keith
2010-04-21 02:12:01 UTC
Permalink
Hello,
I have the following sequence of statements


double MyDouble1;
bool TryParseReturnValue;
String ^ a = gcnew String("123.456");
TryParseReturnValue = Double::TryParse(a,MyDouble1);
MyDouble1 += 1;
a = Double::ToString(MyDouble1,IFormatProvider); // <---- error here


I do not understand what I need to put into the line with the error in order
to make it work. It's clear that "IFormatProvider" is incorrect, but what
are the exact options. Can you help?

Keith
Faisal
2010-04-21 03:42:46 UTC
Permalink
Post by Keith
Hello,
I have the following sequence of statements
double MyDouble1;
bool TryParseReturnValue;
String ^ a = gcnew String("123.456");    
TryParseReturnValue = Double::TryParse(a,MyDouble1);
MyDouble1 += 1;
a = Double::ToString(MyDouble1,IFormatProvider);  // <---- error here
I do not understand what I need to put into the line with the error in order
to make it work.  It's clear that "IFormatProvider"  is incorrect, but what
are the exact options.  Can you help?
Keith  
ToString is not a static member in the Double class. You have to call
MyDouble.ToString(..)
Also you have to specify the format string and culture-specific
formatting info.

see the documentation
http://msdn.microsoft.com/en-us/library/d8ztz0sa.aspx

For eg,

using System::Globalization;

double dbl = 25.693;

String^ specifier = gcnew String(L"G");
String^ str = dbl.ToString( specifier,
CultureInfo::InvariantCulture );
Keith
2010-04-21 13:36:05 UTC
Permalink
Hi Faisal,

Thank you very much for your help. I will follow your steps. I see how
this works, now.

Thank you,

Keith
Post by Faisal
Post by Keith
Hello,
I have the following sequence of statements
double MyDouble1;
bool TryParseReturnValue;
String ^ a = gcnew String("123.456");
TryParseReturnValue = Double::TryParse(a,MyDouble1);
MyDouble1 += 1;
a = Double::ToString(MyDouble1,IFormatProvider); // <---- error here
I do not understand what I need to put into the line with the error in order
to make it work. It's clear that "IFormatProvider" is incorrect, but what
are the exact options. Can you help?
Keith
ToString is not a static member in the Double class. You have to call
MyDouble.ToString(..)
Also you have to specify the format string and culture-specific
formatting info.
see the documentation
http://msdn.microsoft.com/en-us/library/d8ztz0sa.aspx
For eg,
using System::Globalization;
double dbl = 25.693;
String^ specifier = gcnew String(L"G");
String^ str = dbl.ToString( specifier,
CultureInfo::InvariantCulture );
.
Keith
2010-04-22 03:44:02 UTC
Permalink
Hi Faisal,
Thanks very much. I tried this out, and the program now works
I appreciate your help.
Keith

Loading...