On Thu, 2 Dec 2004, bulia byak wrote:
FYI: we have been using Mental's Inkscape::SVGOStringStream for inserting text data into Repr nodes for months now, and it works very, very well.
It works, but the next thing I wanted to do (and I had thought it would be easy with the iostream and Bryce's ftos code) is to drop insignificant 0s from numeric values written to SVG. Can anyone suggest how to do this, if it is possible at all? Those 0s are very annoying.
Yes, the ftos code provides several mechanisms for trimming numbers.
First is a basic rounding thing. In other words, if you give it the number 4.20000 it returns a string "4.2". It also handles 4.200000001 and 4.199999999 this way.
Second is a precision mechanism. This is exactly analogous to printf's capability. You specify the exact number of digits you want and it rounds to that. So you can make it give you 4.20, 0.01, 1.95, 9.99, and 1.00.
Third is a significant figures mechanism. This is somewhat different from precision in that you say "I want N digits worth of information". So if you want to keep 4 sig figs, it will return 123.4, 0.000001111, and 1234000. This approach is common in engineering mathematics, or areas where unit conversions may make a precision-oriented approach cause problems.
You can of course use combinations of the above approaches if desired.
The one thing it doesn't do is localization. For SVG output, though, that's probably undesireable anyway. Would not be hard to add though.
Usage of all of this, plus more detailed examples, are documented in the comments at the top of the ftos.c file.
Bryce x