I want to convert some decimal and floating point numbers to strings. I have been looking for examples of how to do this and came across the following posted example. It seems to be what I want, i.e., String^ out = i.ToString... However, when I run this example I get '02' on the screen, where I would like to see '05'. What am I missing
// example from another question //
using namespace System;
int main()
{
int i = 5;
Console::WriteLine(i.ToString()->Format("02"));
}

Formatting Numbers
Chrismanster
I tried going thru the referenced material, but I didn't really find what I wanted. I never saw anything similar to your use and I did't see any clear and simple example such as seems to exist with printf in the old books I have around. Can you or anyone else suggest a better, simpler reference
Gordon.
basedissonance
Here's a good reference for numeric formats. And here ar the formats being used by datetime.
cheers,
Paul June A. Domag
Patrice RAUCQ
Here's a documentation on how to use the Format method of string class.
cheers,
Paul June A. Domag
Cornel Gav
Gordon.
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
int i = 5;
Console::WriteLine(i.ToString()->Format("00"));
Console::WriteLine(L"Hello World");
return 0;
}
Anish George
Skynyrd
Moving to the .NET development forums since folks there should have more knowledge about the related issues.
Thanks,
Ayman Shoukry
VC++ Team
Norbert Eder
Thanks. Your change worked. Where can I find the list of how Format parameters work
Gordon.
Tracey_nz
Try this instead:
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
int i = 5;
Console::WriteLine(i.ToString("00"));
Console::WriteLine(L"Hello World");
return 0;
}
GregDD
Thanks Ayman Shoukry for moving this. Its your format string that causes the problem here. Try this instead:
using namespace System;
int main()
{
int i = 5;
Console::WriteLine(i.ToString()->Format("00"));
}
cheers,
Paul June A. Domag