Trimming Float Value | Mindfire Solutions

Some times we may need a float value 2.345 instead of complete float value 2.345768.
In such cases we need to trim the float value.The function below demonstrates how it can be done..

function name:                trimFloat( )
param1: float f;        the original float value , i.e., 2.345768
param2:int decimals; how many number of digits we want after the point (.)
return:                       It returns the trimmed float value

float trimFloat(float f, int decimals)
{
    char valueStr[20] = {NULL};
    sprintf(valueStr, "%f", f); 

    int i=0, d=0, sign=0;
    float val = 0.0f;
    float pow = 1.0f;

    int length = strlen(valueStr);
    if (length
150 150 Burnignorance | Where Minds Meet And Sparks Fly!