Join 2 integers (integral and decimal part) to a double in C# -


consider following code:

int integralpart = 123; int decimalpart = 12345; // double desireddouble = 123.12345; 

i create double 2 ints, shown in example.

i know can use double.parse(integralpart.tostring() + "." + decimalpart.tostring()), getting exceptions if application isn't using english default language.

from wording alone, i'd suggest wanted use decimals:

int integralpart = 123; int decimalpart = 12345;  decimal result = decimalpart; while (result>=1m) result/=10m; // caveat: see below  result+=integralpart; 

oops. , there big ambiguity problem others have mentioned. likely, you'd need replace while fixed scale:

result = integralpart + decimalpart / 1000000m; // fixed scale factor 

Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -