Menu

#35 sprintf and exponential notation float values

open
nobody
None
5
2006-08-24
2006-08-24
No

I had some issues with saving exponential notation
floats attributes with TinyXml (near 1e-10 in my case).
Replacing the %f (fixed point notation) by a %g (normal
or exponential notation) in the sprintf call of
TiXmlElement::SetDoubleAttribute(...) seems to fix the
problem.

Regards,
Julien Rouviere

Here is the 'tiny' unified diff for TinyXml 2.4.3
--- X:\tinyxml\tinyxml0.cpp Wed Aug 23 17:10:38 2006
+++ X:\tinyxml\tinyxml.cpp Wed Aug 23 16:52:48 2006
@@ -752,9 +752,9 @@
{
char buf[256];
#if defined(TIXML_SNPRINTF)
- TIXML_SNPRINTF( buf, sizeof(buf), "%f", val );
+ TIXML_SNPRINTF( buf, sizeof(buf), "%g", val );
#else
- sprintf( buf, "%f", val );
+ sprintf( buf, "%g", val );
#endif
SetAttribute( name, buf );
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.