format_float Class Reference

Format a floating point number into a Latex or HTML string. More...

#include <format_float.h>


Detailed Description

This class formats floating point strings into something useful for HTML or Latex documents.

The base-10 logarithm of the smallest and largest numbers to be represented without a string of the form

      $\times 10^{\mathrm{x}}$
      
can be specified in set_exp_min() and set_exp_max(). The number of significant figures can be specified with set_sig_figs() (the default is 5).

Note that this function does not warn the user if the number of significant figures requested is larger than the machine precision.

The format for a normal number is

      prefix (sign-string) number suffix
      
and in scientific notation is
      sci-prefix (sci-sign-string) number times-string 
      exp-prefix (exp-sign-string) exponent exp-suffix sci-suffix
      

Idea for future:
Implement padding with zeros
Idea for future:
Separate out decimal point and make it separate.

Definition at line 78 of file format_float.h.


Public Member Functions

int html_mode ()
 Set HTML mode.
int latex_mode ()
 Set Latex mode.
std::string convert (double x)
 Convert a floating point number to a string.
Set text settings
These are modified by the functions html_mode() and latex_mode()

int set_prefix (std::string prefix)
 set prefix
int set_suffix (std::string suffix)
 Set suffix.
int set_sci_prefix (std::string sci_prefix)
 Set prefix for scientific notation.
int set_sci_suffix (std::string sci_suffix)
 Set suffix for scientific notation.
int set_exp_prefix (std::string exp_prefix)
 Set prefix for exponent.
int set_exp_suffix (std::string exp_suffix)
 Set suffix for exponent.
int set_sign (std::string sign)
 Set sign.
int set_exp_sign (std::string exp_sign)
 Set sign for exponent.
int set_sci_sign (std::string sci_sign)
 Set sign for scientific notation.
int set_times (std::string times)
 Set times.
int set_zero (std::string zero)
 Set zero.
int set_not_finite (std::string not_finite)
 Set string for numbers which are not finite.
Set other settings
These are not modified by the functions html_mode() and latex_mode()

int set_exp_limits (int min, int max)
 Set the exponent limits.
int set_sig_figs (size_t sig_figs)
 Set the number of significant figures.
Get text settings
These are modified by the functions html_mode() and latex_mode()

std::string get_prefix ()
 Get prefix.
std::string get_suffix ()
 Get suffix.
std::string get_sci_prefix ()
 Get prefix for scientific notation.
std::string get_sci_suffix ()
 Get suffix for scientific notation.
std::string get_exp_prefix ()
 Get prefix for exponent.
std::string get_exp_suffix ()
 Get suffix for exponent.
std::string get_sign ()
 Get sign.
std::string get_exp_sign ()
 Get sign for exponent.
std::string get_sci_sign ()
 Get sign for scientific notation.
std::string get_times ()
 Get times.
std::string get_zero ()
 Get zero.
std::string get_not_finite ()
 Get string for numbers which are not finite.
Get other settings
These are not modified by the functions html_mode() and latex_mode()

int get_exp_min ()
 Get minimum exponent.
int get_exp_max ()
 Get maximum exponent.
size_t get_sig_figs ()
 Get sig_figs.

Protected Attributes

Base text settings
std::string prefx
 Prefix (default "").
std::string suffx
 Suffix (default "").
std::string sgn
 Sign string (default "-").
std::string sci_sgn
 Sign string in scientific mode (default "-").
std::string exp_sgn
 Sign string for exponent in scientific mode (default "-").
std::string sci_prefx
 Prefix in scientific mode (default "").
std::string sci_suffx
 Suffix in scientific mode (default "").
std::string exp_prefx
 Exponent prefix (default "").
std::string exp_suffx
 Exponent suffix (default "").
std::string tmes
 Times symbol for scientific mode (default " x ").
std::string not_finte
 String for numbers which are not finite (default "Nan").
std::string zeros
 String for zeros (default "0").
Other settings
size_t sig_fgs
 Number of significant figures (default 5).
int ex_mn
 Lower limit for automatic mode (default -2).
int ex_mx
 Upper limit for automatic mode (default -2).
bool pad_zeros
 If true, pad with zeros (default false).

Member Function Documentation

int html_mode (  )  [inline]

int latex_mode (  )  [inline]


The documentation for this class was generated from the following file:

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page