Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
why this wierd convert double to string happens?



I use win 8.1 ,visual studio 2019 in laptop it is wierd.
i use win 10 , visual studio 2019 in PC and it is ok.

What I have tried:

C#
double d=1.2;
string sWierd =""+d;//s=1/2
string sOk=d.ToString();//s=1.2

//both are not "1.2" for me so that is weird.
//weird one is "1/2". it changes dot to foreslash
Posted
Updated 5-May-19 17:53pm
v3

In Persian, a slash is a decimal separator

Decimal separator - Wikipedia[^]

My guess would be that one method is using your locale and the other is not, for some reason?
 
Share this answer
 
Comments
4L4K1 6-May-19 1:41am    
in my laptop default keyboard language is Persian and before debugging i set it to English. how it can effects at code running?
Christian Graus 6-May-19 2:38am    
Sounds like one method finds the default and one uses the current setting? Sounds like an interesting C# bug......
What are you talking "weird"? There's nothing weird going on. Both strings are "1.2".

If you're talking about doing this:
C#
string sWeird = "" + d;

and wondering why it's working, it's because the .ToString() is being implicitly called on d to make the expression string.Empty + d work.
 
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