Jump to content
  • Advertisement
Sign in to follow this  
makingroulette

math class .net framework library

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!