Skip to content

Commit 46897c8

Browse files
authored
Merge pull request #112 from summitn/master
Support for float
2 parents a9b3430 + e5bbcc8 commit 46897c8

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/LitJson/JsonMapper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,11 @@ private static void RegisterBaseImporters ()
674674
RegisterImporter (base_importers_table, typeof (double),
675675
typeof (decimal), importer);
676676

677+
importer = delegate (object input) {
678+
return Convert.ToSingle((double)input);
679+
};
680+
RegisterImporter(base_importers_table, typeof(double),
681+
typeof(float), importer);
677682

678683
importer = delegate (object input) {
679684
return Convert.ToUInt32 ((long) input);
@@ -744,6 +749,12 @@ private static void WriteValue (object obj, JsonWriter writer,
744749
return;
745750
}
746751

752+
if (obj is Single)
753+
{
754+
writer.Write((float)obj);
755+
return;
756+
}
757+
747758
if (obj is Int32) {
748759
writer.Write ((int) obj);
749760
return;

src/LitJson/JsonWriter.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,17 @@ public void Write (double number)
339339
context.ExpectingValue = false;
340340
}
341341

342+
public void Write(float number)
343+
{
344+
DoValidation(Condition.Value);
345+
PutNewline();
346+
347+
string str = Convert.ToString(number, number_format);
348+
Put(str);
349+
350+
context.ExpectingValue = false;
351+
}
352+
342353
public void Write (int number)
343354
{
344355
DoValidation (Condition.Value);

0 commit comments

Comments
 (0)