Sign in to follow this  
makingroulette

math class .net framework library

Recommended Posts

I am trying to use the Math class to perform rounding of numbers. The Math class contains various rounding functions. Math::Round(3.44, 1); //Returns 3.4. Math::Round(3.45, 1); //Returns 3.4. Math::Round(3.46, 1); //Returns 3.5. The problem is that I don't know what header file I have to include, if any at all. just using the Math namespace specifier doesn;t seem to be enough. I don;t have any experience with the .NET framework library. Hope you can help

Share this post


Link to post
Share on other sites
Since you mentioned header files I'm assuming that you're using managed C++. You don't need header files just a reference to mscorlib.dll (#using <mscorlib.dll>) and namespace references to the math library:


#using <mscorlib.dll>

int main()
{
System::Console::WriteLine( System::Math::Round( 3.44, 1 ).ToString() );
System::Console::WriteLine( System::Math::Round( 3.45, 1 ).ToString() );
System::Console::WriteLine( System::Math::Round( 3.46, 1 ).ToString() );

return 0;
}

Share this post


Link to post
Share on other sites
ive just tried that and i didn;t work.

c:\Projects\PickingConsoleApplication\main.cpp(3) : fatal error C1190: managed targeted code requires '#using <mscorlib.dll>' and '/clr' option

and got this message.

im not sure if im using managed C++

im creating an empty console application

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
throw the /clr switch in the compiler.
make sure System.dll is referenced in the project.

Share this post


Link to post
Share on other sites
I put the above code in a file called c:\test\test.cpp

In a DOS window (Start->Run->cmd.exe->OK) I cd to the directory where test.cpp is and initialize the VS 2003 environment:

cd c:\test
call "%VS71COMNTOOLS%vsvars32.bat"


I then compile the program:

C:\test> cl /clr test.cpp

and run it:

C:\test> test.exe
3.4
3.4
3.5

bold is what I typed.

Share this post


Link to post
Share on other sites
makingroulette, you can also add the /clr switch from within Visual Studio:

1. Right-click on your project in Solution Explorer (it should be contained within a 'Solution').
2. Click Properties.
3. Make sure General is selected on the left.
4. Set "Use Managed Extensions" to yes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this