Login Page - Create Account

Support Board


Date/Time: Wed, 15 Jan 2025 11:56:32 +0000



Post From: Question About Float Precision in Sierra Chart API(ACSIL)

[2024-08-06 00:59:48]
User856649 - Posts: 5
I would like to bring up a common issue with floating-point precision in C++/SC study programming.

Here's a quick C++ code snippet:

---------------------------------------------------------
float y = 0.30f + 0.40f;

if (y == 0.70f)
cout << "True" <<endl;
else
cout << "False" << endl;
-------------------------------------------------

output:
False
----------------------------------------------------

I expected y to be 0.70f, so I thought output could be "True". However, due to how floating-point math works, y may not exactly equal 0.70f, which can lead to the output being "False" instead. this issue is quite common in programming, so that C# has a build-in type--decimal to avoid this issue.

I've noticed that the Sierra Chart API(ACSIL) mainly uses float and double types for numbers/prices. Given the importance of precision in trading software, I'm curious if the Sierra Chart API accounts for float precision issues. Are there any built-in features or best practices to help developers avoid problems related to floating-point calculations?

Thanks for your help.