I want to format a string number. For example:
double number="118176";
It should look like 1181.71 or 1181,71.
I couldn’t find any format type. I tried some of format types as ToString("#,0") but it didn’t work.
Thanks for any advice.
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.
First of all: a
doublevariable can not take a string. But that aside, something like this should help:This takes the number and creates a string from it using the decimal number format with 2 decimal places.
What you didn’t say is why you expect the integer
118176to magically turn into a double with two decimals? The only way would beEDIT
Doing what you describe in your comment is a bit more complex:
This converts the number in
priceDoubleto a string with the value formatted like a currency. If you do not want the currency symbol, use the following: