Menu

SetAttribute(const char* name, double val)?

Developer
2003-12-19
2003-12-22
  • Igor Pavlov

    Igor Pavlov - 2003-12-19

    Hi.
    There are set of methods for string's, int's and double's in the TiXmlAttribute class. There are full support for string's and int's in the TiXmlElement class, but for double's there are only limited feature set. My question is why there are no methods exist like:
    void TiXmlElement::SetAttribute(const char* name, double val)?

     
    • B Sizer

      B Sizer - 2003-12-19

      Probably because 99% of people don't need them. They're easy enough to add in if you want though.

      void TiXmlElement::SetAttribute( const char * name, double val )
      {   
          char buf[64];
          sprintf( buf, "%f", val );
          SetAttribute( name, buf );
      }

      The problem you have now is that the precision/number of decimal places of the output is decided in the library, which may not suit everybody. So it might be better to use your own wrapping function to generate strings from floats/doubles with as many decimal places as you need, and no more.

       
    • Igor Pavlov

      Igor Pavlov - 2003-12-22

      Thank's for reply.
      I am already realize the solution that you suggest.
      And now I have another problem. The library did not support direct writing of double values but it can read them. The problem is - system locale. If i write the value (ex. 7.31) on system with '.' decimal symbol and read that data on system with ',' decimal symbol than i get a wrong result (7.0 vs 7.31). It will be much better if the library completely omit the support of floating point numbers or have more customizable support to reading such values.

       

Log in to post a comment.

MongoDB Logo MongoDB