Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have two numbers like(800022 and 900002). I want to convert it with two decimal like (8.2.2 and 9.0.2) that is I want to put decimal after first digit, before last and before last second digit, so can any one help me to solve this issue ?

Thanks,
Posted
Comments
Debabrata_Das 6-Jun-14 3:49am    
Hi Priyanka, I saw that you got your answer. But I could not understand the conversion logic. Can you please help me in understanding it? I'm not looking for any programmatic solution. just want to understand the logic of the problem.
Input | Output
8000022 | 8.2.2
9000002 | 9.0.2
1000111 | ?

- DD

Try this code. Remember this just the logic not necessary the optimized code.

C#
int a = 800022;
char []c=a.ToString().Reverse().ToArray();
string s = c[5] + "." +c[1]+ "."+ c[0];
 
Share this answer
 
Comments
Priyanka Bhawsar 6-Jun-14 1:44am    
Thankyou so much, its the perfect logic. :)
ArunRajendra 6-Jun-14 1:49am    
Mark the solution as accepted if you are happy with solution. Optionally you can rate it as well with 5 being highest.
[no name] 6-Jun-14 1:57am    
This is also correct but why did you reverse it?
Try this code:
C#
int number = 900002;
string n = number.ToString();
n = n[0] + "." + n[n.Length - 2] + "." + n[n.Length - 1];

This code will work in any number of digits.
 
Share this answer
 
v2
Comments
Priyanka Bhawsar 6-Jun-14 1:54am    
nice one, its working I needed that.Thank you

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