Click here to Skip to main content
15,905,325 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai Friends ,
I am having a number say for eg : 12345.67 and what i need is to Reverse the number to 76.54321 ........... Is There any idea since I have idea only on reversing a int number . I am unable to find the solution for Double ......................
Posted
Comments
[no name] 24-Jun-13 7:33am    
Simple, reverse the string 12345.67 then convert the result to double. If you can do it for an int, you should be able to do it for a double.
Rajesh Anuhya 24-Jun-13 7:40am    
You can post it as a answer
--RA

Hi,

Try this:
C#
double d = 12345.67;
string reversedStr = new string(d.ToString().Reverse().ToArray());
double reversedDouble;
if (double.TryParse(reversedStr, out reversedDouble))
{
    // now, reversedDouble is the reversed double
}
else
{
    // unable to reverse the double
}

Hope this helps.
 
Share this answer
 
Comments
MurugappanCTS 24-Jun-13 7:40am    
thanks
Thomas Daniels 24-Jun-13 7:41am    
You're welcome!
Convert to string, reverse and convert it back to double. To write reverse function follow this link. http://stackoverflow.com/questions/228038/best-way-to-reverse-a-string[^]
 
Share this answer
 
Comments
MurugappanCTS 24-Jun-13 7:40am    
thanks for ur help
ArunRajendra 25-Jun-13 4:40am    
Welcome :)
Hello,

Try this:

C#
void Main()
{
    double d = 12345.67;
    Console.WriteLine("Reversed: {0}", ReverseNumber(d));
}

double ReverseNumber(double number)
{
    return double.Parse(ReverseString(number.ToString()));
}

string ReverseString( string s )
{
    char[] charArray = s.ToCharArray();
    Array.Reverse( charArray );
    return new string( charArray );
}


Cheers,
JAFC
 
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