1. ## float multiplication problems

The exercise:

Write a function called strToFloat that converts a character string into a floating point value. Have the function accept an optional leading minus sign. So, the call

strToFloat("-867.6921")

should return the value -867.6921.
The test value is 123.123 in character format.

All is going well except something with my last subroutine with switch case statement multiplicationa is off. Got me scratching my head. Here's the output.

Code:
```The number of decimal places are: 3
Decimal character string extracted to buffer: 123123
Decimal result=123123
Converted completely back to decimal: 123.123001```
Here is the switch case structure. I'm not sure if its my initializing of floats I'm doing wrong or what.

Code:
```void decPlaceMult(double number)
{

switch(count)
{
case 1:
break;

case 2:
break;

case 3:
break;

case 4:
break;

case 5:
break;

default:
break;
}

printf("Converted completely back to decimal: %f",answer);
getchar();

return;
}```
Any insight greatly appreciated.

2. I don't see where "count" is defined...

But as for your problem...that function would be called atof().

Code:
```float strToFloat(char *input)
{
return (float)(atof(input));
}```

3. Originally Posted by memcpy
I don't see where "count" is defined...

But as for your problem...that function would be called atof().

Code:
```float strToFloat(char *input)
{
return (float)(atof(input));
}```

Yeah that's cheating.

And count is global.

4. I've got one word for you: Rounding Errors

EDIT: Ok, maybe two words

5. Originally Posted by GReaper
I've got one word for you: Rounding Errors

EDIT: Ok, maybe two words
How can I get it to round? I browsing the book here but cant see a solution to it in the float references.

6. Originally Posted by A34Chris
How can I get it to round?
You can't, at least not the way you think. You can just ask from printf to only print eg 3 fractional digits with "%.3f"

7. As long as the input isn't too crazy I would actually store the place values as a (big) integer and then put the decimal point where it needs to be by multiplying by a power of ten, and maybe -1.0 for the sign. Making sure when I multiply that the result is a floating point of course.

8. ok thanks for your guys input.