/* Formats a floating point value in one of the following formats   */
/* (i)  If mode == 0, use floating point format with "precision"    */
/*      places after the decimal point.                             */
/* (ii) If mode == 1, use scientific notation with one place before */
/*      the decimal point and "precision" places after.             */

#include "plplot.h"
#include <stdio.h>
#include <string.h>

void plform(value,mode,prec,result)
float value;
int mode, prec;
char *result;
{
      int j, expon;
      char form[10];
      char temp[30];

      if (mode == 0) {
        sprintf(form,"%%-.%df",prec);
        sprintf(temp,form,value);
        strcpy(result,temp);
      }
      else {
        sprintf(form,"%%-.%dE",prec);
        sprintf(temp,form,value);
        j = strpos(temp,'E') + 1;
        if (j == 0) fatal("Unrecognized scientific notation");
        sscanf(&temp[j],"%d",&expon);
        sprintf(form,"%-d",expon);
        strcpy(&temp[j-1],"x10\\u");
        strcat(temp,form);
        strcpy(result,temp);
      }
}

