Login Page - Create Account

Support Board


Date/Time: Fri, 29 Nov 2024 14:35:53 +0000



[Programming Help] - Pers Double not providing the expected outcome.

View Count: 303

[2023-01-31 08:47:00]
User92573 - Posts: 530
Dear Support

I'm obviously missing something simple but as I'm not a programmer this is a little confusing.

Can someone help explain why the increased precision results in a 0?



float& Simple_calc1 = sc.GetPersistentFloat(1);
double& Simple_calc2 = sc.GetPersistentDouble(1);

Simple_calc1 = 10/5; // ignoring use of 10.0f/5.0f
Simple_calc2 = 10/5;


msg.Format("Simple Calculation using float = %f",Simple_calc1);
sc.AddMessageToLog(msg,1);

msg.Format("Simple Calculation using double = %d",Simple_calc2);
sc.AddMessageToLog(msg,1);


Message Log output:


Simple Calculation using float = 2.0
Simple Calculation using double = 0 //?



Many thanks for any help.
[2023-01-31 08:57:45]
User431178 - Posts: 544
When using the format function d means signed integer, you need to use f in both cases.
[2023-02-01 08:56:58]
User92573 - Posts: 530
Thank you, for some reason I'd made a mental note %D was a double hence greater precision, not an integer.

When I did a quick search there it was, Int Base 10. So, output was consistent with C++ as opposed to my mental note.

Many thanks for replying.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account