Programming Guide |
Writes a real number to a field
int sm_dtofield(int field_number, double value, char *format);int sm_e_dtofield(char *field_name, int element, double value, char *format);int sm_i_dtofield(char *field_name, int occurrence, double value, char *format);int sm_n_dtofield(char *field_name, double value, char *format);int sm_o_dtofield(int field_number, int occurrence, double value, char *format);
field_name
field_number
- The field to receive
value
.element
- The element in
field_name
to receivevalue
.occurrence
- The occurrence in the field to receive
value
.value
- The real number data to write.
format
- Specifies the format to apply to
value
. To supply a value of 0, cast the argument as follows:(char *)0
.
C only
sm_dtofield
converts the real numbervalue
to user-readable format as specified by format. It then moves this value into the specified field with a call to sm_amt_format. If theformat
string is empty and the field'sdata_formatting
property is set toPV_NUMERIC
, Panther uses the field's numeric formatting subproperties to determine precision. Ifdata_formatting
is set toPV_NONE
, Panther uses the precision set by the behavior variableDECIMAL_PLACES
.You can round the number of decimal places to
n
places with the format string"%.
n
f
". To truncate, use the format string"%t.
n
f
".
/* Place the value of pi on the screen, using the
* formatting attached to the field. */
sm_n_dtofield("pi", 3.14159, (char *)0);
/* Do it again, using only three decimal places.
sm_n_dtofield("pi", 3.14159, "%5.3f");