# math class .net framework library

This topic is 4762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 on other sites
you have to use managed c++ to access .net, unless you are using C#, etc.

##### Share on other sites
throw the /clr switch in the compiler.
make sure System.dll is referenced in the project.

##### 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 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 on other sites
Thanks for your help i got it all working.