Forum Moderators: open
using System;
using System.Globalization;
class FloatToString
{
static void Main(string[] args)
{
NumberFormatInfo nfi = CultureInfo.CurrentCulture.NumberFormat;
float Pi = 22/7;
Console.WriteLine(Pi.ToString("n", nfi)); // pass number format
// returns 3.00
}
}
The other format flags are:
c - currency
d - decimal
e - exponential
f - fixed point
g - general
n - number
r - roundtrip
x - hexidecimal
Take a look at the NumberFormatInfo Class
This VB code returned: 3.14285714285714
Dim Pi As Double
Pi = 22 / 7
Response.Write(Pi.ToString)
Alternatively, does the C++ float offer optional parameters at declaration? Since 22/7 has decimals, if 3 is being returned then it's the variable that's truncating it.