wiki:Docs/Prog/Manual/ApplicationLibraries/lib825ev/Weight/FormatWt

Version 8 (modified by Don Wilson, 3 years ago) ( diff )

--

FormatWt

Format a string representation of the specified weight

string FormatWt(float fWt, uint8 byIntv, uint8 byDec, int nLen = 7);

char* FormatWt(float fWt, uint8 byIntv, uint8 byDec, char* pszWt, int nLen = 7);

Parameters

  • fWt - weight value to format
  • byIntv - interval such as 20 for twenty pound intervals, should normally be (1, 2, 5, 10, 20, 50, or 100).
  • byDec - number of decimal places (0 - 4).
  • nLen - length to format the string, spaces will be padded to the left.
  • pszWt - buffer to copy weight data to.

Return Value

  • Returns the string formatted weight. char* return override returns a pointer to the passed pszWt parameter where the result is stored.

Remarks

This will format the provided weight value into appropriate divisions and add zeros for zero weight if necessary based on the interval. For example, if an interval of 20 lb is specified and the weight is zero the output will be " 00".

For most applications the interval should be a value based on 1, 2, or 5. For example the interval may be 1, 2, 5, 10, 20, or 50. (Some jurisdictions may not have this as a legal requirement, but other interval values will result in unusual weight incrementing behavior such as 3, 6, 9, 12, 15, 18, ... and adding or subtracting two of these weight values may result in a value that does not match the interval).

If the interval is multiple digits such as 10 the decimal place parameter must be zero.

Examples

float wt = 12055;
string strWt = FormatWt(wt, 20, 0);
DisplayText(0, 0, strWt);
// Will display 12060
float wt = 12055;
char szWt[20];
FormatWt(wt, 20, 0, szWt);
DisplayText(0, 0, szWt);
// Will display 12060
float wt = 12.137;
char szWt[20];
FormatWt(wt, 2, 2, szWt);
DisplayText(0, 0, szWt);
// Will display 12.14

See Also

Note: See TracWiki for help on using the wiki.