зеркало из https://github.com/stride3d/SharpYaml.git
Fix issue when serializing float/double with exponents
This commit is contained in:
Родитель
c19f967a74
Коммит
89187f383e
|
@ -47,6 +47,7 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Security.Policy;
|
||||
using NUnit.Framework;
|
||||
using SharpYaml.Serialization;
|
||||
using SharpYaml.Serialization.Serializers;
|
||||
|
@ -257,6 +258,30 @@ UInt64: 8
|
|||
SerialRoundTrip(settings, text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class ObjectFloatDoublePrecision
|
||||
{
|
||||
public float Float { get; set; }
|
||||
|
||||
public double Double { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFloatDoublePrecision()
|
||||
{
|
||||
var settings = new SerializerSettings() { LimitPrimitiveFlowSequence = 20 };
|
||||
settings.RegisterTagMapping("ObjectFloatDoublePrecision", typeof(ObjectFloatDoublePrecision));
|
||||
|
||||
var text = @"!ObjectFloatDoublePrecision
|
||||
Float: 1E-05
|
||||
Double: 1E-05
|
||||
".Trim();
|
||||
|
||||
SerialRoundTrip(settings, text);
|
||||
}
|
||||
|
||||
public class MyObjectAndCollection
|
||||
{
|
||||
public MyObjectAndCollection()
|
||||
|
|
|
@ -168,14 +168,16 @@ namespace SharpYaml.Serialization.Serializers
|
|||
/// <returns></returns>
|
||||
private string AppendDecimalPoint(string text )
|
||||
{
|
||||
if (text.Contains("."))
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
var c = text[i];
|
||||
if (c == 'e' || c == 'E' || c == '.')
|
||||
{
|
||||
return text;
|
||||
}
|
||||
else
|
||||
{
|
||||
return text + ".0";
|
||||
}
|
||||
|
||||
return text + ".0";
|
||||
}
|
||||
|
||||
public override string ConvertTo(ref ObjectContext objectContext)
|
||||
|
|
Загрузка…
Ссылка в новой задаче