I have a string which needs a decimal place inserted to give a precision of 2.
3000 => 30.00 300 => 3.00 30 => .30
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Given a string input, convert to integer, divide by 100.0 and use String.Format() to make it display two decimal places.
Smarter and without converting back and forth – pad the string with zeros to at least two characters and then insert a point two characters from the right.
Pad to a length of three to get a leading zero. Pad to precision + 1 in the extension metheod to get a leading zero.
And as an extension method, just for kicks.
Note: PadLeft() is correct.