home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Conic Sections 0.9.2 / Sources / Misc.cpp < prev    next >
Encoding:
Text File  |  1997-05-18  |  592 b   |  33 lines  |  [TEXT/CWIE]

  1. //Copyright (c) 1997 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include <QuickDraw.h>
  5. #include "Misc.h"
  6. #include "CLStrStuff.h"
  7.  
  8. unsigned char *gcvt( float num, int precision ) {
  9.     int temp;
  10.     Str32 buf;
  11.  
  12.     if( num < 0 ) {
  13.         StrCpy( buf, "\p-" );
  14.         num = -num;
  15.     } else
  16.         buf[0] = 0;
  17.     StrCat( buf, IToA( (int)num ) );
  18.     StrCat( buf, "\p." );
  19.     temp = precision-buf[0];
  20.     while( temp-- ) {
  21.         num -= (int)num;
  22.         num *= 10;
  23.         if( !(int)num )
  24.             StrCat( buf, "\p0" );
  25.         else
  26.             StrCat( buf, IToA( (int)num ) );
  27.     }
  28.     while( buf[buf[0]] == '0' )
  29.         buf[0]--;
  30.     if( buf[buf[0]] == '.' )
  31.         buf[0]--;
  32.     return( buf );
  33. }