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

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -