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 7 Years Ago by Lukezzz: n/a

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 7 Years Ago by William Hemsworth: n/a

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.