Jump to content
Medved Trader Forums
Jason

Rounding?

Recommended Posts

Hello,

I have a scenario where the code my paintbar is producing a number like so... 0.039996. How do I go about rounding this to 0.04? Of course, if I had a number like 0.0312 I'd want this round down to 0.03.

Thank you!

Share this post


Link to post
Share on other sites

one of the benefits of the Paintbar/Scan code using C# is that you get the full use of the C# language and it is fully documented. What you are looking for is the Math.Round(....) function

https://docs.microsoft.com/en-us/dotnet/api/system.math.round?view=netframework-4.7.2

There are a lot of options but you can just use the simplest version. If your variable holding the value is myVariable, you would just use Math.Round(myVariable)

or if your computation is A * B + C, you can just replace that with Math.Round(A * B + C)

Share this post


Link to post
Share on other sites

Thank you for the confirmation. I suspected and hoped that was the case. I'm used to working in a scripting language which has some wonky results when it comes to the functions used for this purpose and didn't want to spend a huge amount of time testing and wondering how it would work in MT.

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...