StringFormatter provides Python's % style string formatting services.
예제 #1
0
 /// <summary>
 /// Write value in pickle decimalnl_short format.
 /// </summary>
 private void WriteFloatAsString(object value)
 {
     Debug.Assert(Ops.GetDynamicType(value).Equals(TypeCache.Double));
     // 17 digits of precision are necessary for accurate roundtripping
     StringFormatter sf = new StringFormatter("%.17g", value);
     sf.TrailingZeroAfterWholeFloat = true;
     Write(sf.Format());
     Write(Newline);
 }
예제 #2
0
 public static string ToString(double x)
 {
     StringFormatter sf = new StringFormatter("%.12g", x);
     sf.TrailingZeroAfterWholeFloat = true;
     return sf.Format();
 }
예제 #3
0
 public static string ToString(float x)
 {
     // Python does not natively support System.Single. However, we try to provide
     // formatting consistent with System.Double.
     StringFormatter sf = new StringFormatter("%.6g", x);
     sf.TrailingZeroAfterWholeFloat = true;
     return sf.Format();
 }
예제 #4
0
 /// <summary>
 /// Write value in pickle decimalnl_short format.
 /// </summary>
 private void WriteFloatAsString(CodeContext/*!*/ context, object value) {                
     Debug.Assert(DynamicHelpers.GetPythonType(value).Equals(TypeCache.Double));
     // 17 digits of precision are necessary for accurate roundtripping
     StringFormatter sf = new StringFormatter(context, "%.17g", value);
     sf._TrailingZeroAfterWholeFloat = true;
     Write(context, sf.Format());
     Write(context, Newline);
 }