0

I am trying to Convert this Long String to an integer but when running the code, I get an error that tells that the inputstring is in an incorrect format.

How can I convert this string so I will get the ouput integer: 41517 ?

String^ ba = "41516.7095211088";
                int bb = Convert::ToInt32(ba);
                MessageBox::Show(Convert.ToString(bb));

Edited by Lukezzz: n/a

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Lukezzz
0

Remember, you're using managed C++, so you need to use managed types.

String^ ba = "41516.7095211088";
Double bb = Convert::ToDouble( ba );
Int32 rounded = (Int32)Math::Round( bb );
MessageBox::Show( rounded.ToString() );

Edited by William Hemsworth: n/a

0

Yes, then I understand. I have to first convert it to a double and than round it, casting it to Int32.

It worked fine.
Thank you.

Remember, you're using managed C++, so you need to use managed types.

String^ ba = "41516.7095211088";
Double bb = Convert::ToDouble( ba );
Int32 rounded = (Int32)Math::Round( bb );
MessageBox::Show( rounded.ToString() );
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.