W William Stacey [MVP] Jun 14, 2004 #1 If val is a long, what is the String format conversion of this in c#? TIA! sprintf(retbuf,"%d.%.2d", val/100, val%100);
If val is a long, what is the String format conversion of this in c#? TIA! sprintf(retbuf,"%d.%.2d", val/100, val%100);
A adnan boz Jun 14, 2004 #2 Hi, Without a regular expression, it could look like this retbuf = Math.Abs(val/100) + "." + val%100; But this will give the same result retbuf = Math.Round((decimal)val/100,2).ToString(); Good Luck Adnan
Hi, Without a regular expression, it could look like this retbuf = Math.Abs(val/100) + "." + val%100; But this will give the same result retbuf = Math.Round((decimal)val/100,2).ToString(); Good Luck Adnan
? =?ISO-8859-2?Q?Marcin_Grz=EAbski?= Jun 14, 2004 #3 Hi Hi, Without a regular expression, it could look like this retbuf = Math.Abs(val/100) + "." + val%100; But this will give the same result retbuf = Math.Round((decimal)val/100,2).ToString(); Good Luck Adnan Click to expand... Adnan solution can hit in your demand, but you should look for "sprintf" equivalent in C# String.Format(...) <or Double.ToString(...)>. More precise information you can find in "Formatting Overview" & "NumberFormatInfo" in .NET docs. I can recomend: // eg. val=1234560; double valDbl=val/100.0; string strVal1=valDbl.ToString("0.00"); // or string strVal2=String.Format("{0}.{1}" , val/100 , ((int)(val%100)).ToString("00")); Regards Marcin
Hi Hi, Without a regular expression, it could look like this retbuf = Math.Abs(val/100) + "." + val%100; But this will give the same result retbuf = Math.Round((decimal)val/100,2).ToString(); Good Luck Adnan Click to expand... Adnan solution can hit in your demand, but you should look for "sprintf" equivalent in C# String.Format(...) <or Double.ToString(...)>. More precise information you can find in "Formatting Overview" & "NumberFormatInfo" in .NET docs. I can recomend: // eg. val=1234560; double valDbl=val/100.0; string strVal1=valDbl.ToString("0.00"); // or string strVal2=String.Format("{0}.{1}" , val/100 , ((int)(val%100)).ToString("00")); Regards Marcin
M mikeb Jun 14, 2004 #4 William said: If val is a long, what is the String format conversion of this in c#? TIA! sprintf(retbuf,"%d.%.2d", val/100, val%100); Click to expand... Something like: retbuf = String.Format( "{0}.{1:00}", val/100, val%100);
William said: If val is a long, what is the String format conversion of this in c#? TIA! sprintf(retbuf,"%d.%.2d", val/100, val%100); Click to expand... Something like: retbuf = String.Format( "{0}.{1:00}", val/100, val%100);
W William Stacey [MVP] Jun 14, 2004 #5 yes. Thanks. -- William Stacey, MVP mikeb said: Something like: retbuf = String.Format( "{0}.{1:00}", val/100, val%100); Click to expand...
yes. Thanks. -- William Stacey, MVP mikeb said: Something like: retbuf = String.Format( "{0}.{1:00}", val/100, val%100); Click to expand...