Hi David

I'll chime in here but I'm often on the wrong track compared to the talent
you'll find on this list.   My float experience is from older os'es ie pre
3.5
using newfloatmgr.h.  not knowing what is passed to your .prc i'll toss
you this incase it's a FloatType.

This function snippit returns a text string from a float type which I'm
certain to be flamed over but 'ya never know what may be helpful
so here goes....     Also have a gander at the Calc samples for
handling FloatTypes.   Accuracy and rounding are issues not
addressed in this func....



/***********************************************************************
 * FUNCTION:   DisplayFloatingPoint
 *     Displays a full floating point number
 ************************************************************************/
static void DisplayFloatingPoint(Word fieldId ){
FormPtr frm = FrmGetActiveForm();
Boolean handled = false;
 DWord  Mantissa = 0;
 SWord Exponent = 0;
 SWord Sign = 0;
 SWord DecimalPos = 0;
 Char CharDecimal='.';
 Char CharZero='0';
int X;
int indexX;
int indexY;
int INDEX;

 Char mantissaStr[10]="\0\0\0\0\0\0\0\0\0\0";  // allow for '\0'
 Char dispMantissaStr[10]="\0\0\0\0\0\0\0\0\0\0"; // allow for '\0'  also
+/-


// convert the FloatType to base 10
  FplBase10Info(Rally.OCF, &Mantissa, &Exponent, &Sign);

 if (Mantissa == 0) {  //  || Exponent < -9  less than -15 is out of range
  StrCopy (mantissaStr, "000000000");
   Exponent = -2;       // force "zero" to be displayed as 00.00
   Sign = 0;    // clear the sign (FloatMgr bug workaround)
  } else
   StrIToA(mantissaStr, Mantissa);  // got a value dump into buf

// pad the display string with leading zeros
StrCopy (dispMantissaStr, "000000000");

// ok these numbers are beyond the manstring so place decimal .###
// and determine placement of int's
if (Exponent >= -15 && Exponent <= -8){
dispMantissaStr[0] = CharDecimal;  // forced up front
switch (Exponent)
 {        // index to start dumping numbers
  case -15:
   INDEX = 8;  break;
  case -14:
   INDEX = 7;  break;
  case -13:
   INDEX = 6;  break;
  case -12:
   INDEX = 5;  break;
  case -11:
   INDEX = 4;  break;
  case -10:
   INDEX = 3;  break;
  case -9:
   INDEX = 2;  break;
  case -8:
   INDEX = 1;  break;   // yes we need some formula here
  default:                     // or switch case for all exponents
  break;
  }

 indexY = 0;
  for (X=0; X<9; X++)
          if (X == INDEX)  // positive or negative number?
    dispMantissaStr[ INDEX++ ] =  mantissaStr[ indexY++ ];
   dispMantissaStr[9] = '\0'; // terminate

  SetFieldTextFromStr(fieldId, dispMantissaStr); // display value
 return;  // were done...
  }

// @ -7 we have some whole numbers #.####  -6  ##.######   - 5
#.#####   -4 ####.###
DecimalPos =  8 + Exponent; // indexes -7@0   -1@6

indexX=0;
for (X=0; X<9 ;
{  
  if (X == DecimalPos)
  dispMantissaStr[indexX++] = CharDecimal;
 else
  if (X > DecimalPos)
  dispMantissaStr[ indexX++ ] =  mantissaStr[ X-1 ];  // keep aligned with the source 
buf
 else
  if (indexX < 9)
  dispMantissaStr[ indexX++ ] =  mantissaStr[ X  ];
  }
 dispMantissaStr[9] = '\0'; // terminate
SetFieldTextFromStr(fieldId, dispMantissaStr); // display value

return; // fini
}
 





-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to