Click here to Skip to main content
15,919,331 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
While coding some libraries I ran into some errors with my string format.
I don't really know how to solve this, or anything about string formatting.

My Code:
C#
public float getMeleeCB(float attk, float str, float def, float hp, float pray)
        {
            return (Convert.ToSingle((double)Convert.ToDecimal("0.3f") * (1.3 * (attk + str) + def + hp + (.5 * pray))));
            //example of use: string test = "Melee Combat Level: "+getMeleeCB(60,53,58,53,47).ToString();
        }



Run-Time Error Message:
Format-Exception was unhandled - input string was not in a correct format


How do I format it to work the way I set it up?
Posted
Comments
Sergey Alexandrovich Kryukov 19-Jun-12 14:36pm    
"I don't really know" is not a valid question. If you don't, learn it, no wait.
--SA
[no name] 19-Jun-12 15:39pm    
"0.3f" is not a valid input. Get rid of the "f" and it should work.

Attach a debugger and you will find that some of your parameters isn't a correct float value.

You should use TryParse[^] if you are not sure about that the inputs are validated.

Hope this helps!
 
Share this answer
 
This part will always throw an exception: Convert.ToDecimal("0.3f"). The 0.3f is something the compiler recognizes, but should not be used in the code.Other stuff seems to be ok.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900