sprintf giving different results when used in vs2013 and vs2019.

Copper Contributor

Hi Team, 

I have a sample code wherein I am converting a double to string using sprintf.

The same code is used in two different code bases, one of which is compiled using vs2013 and other using vs2019. I see different results in both the case. Following is the piece of code:


sprintf(buf, p > 0 ? "%#.*f" : "%.*f", p, d);

where p=8 and d is variable of type double and its value is 11111111111222222222222222. buf is char array of size  320


Value of buf in vs2019 1111111111111222163202874213048930610238868946944.00000000

 value of buf in vs2013:



Can you please explain. Also what can we use as a replacement of sprintf?

0 Replies