Skip to content

Commit

Permalink
Merge pull request #112 from summitn/master
Browse files Browse the repository at this point in the history
Support for float
  • Loading branch information
devlead committed Jan 22, 2020
2 parents a9b3430 + e5bbcc8 commit 46897c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/LitJson/JsonMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,11 @@ private static void RegisterBaseImporters ()
RegisterImporter (base_importers_table, typeof (double),
typeof (decimal), importer);

importer = delegate (object input) {
return Convert.ToSingle((double)input);
};
RegisterImporter(base_importers_table, typeof(double),
typeof(float), importer);

importer = delegate (object input) {
return Convert.ToUInt32 ((long) input);
Expand Down Expand Up @@ -744,6 +749,12 @@ private static void RegisterBaseImporters ()
return;
}

if (obj is Single)
{
writer.Write((float)obj);
return;
}

if (obj is Int32) {
writer.Write ((int) obj);
return;
Expand Down
11 changes: 11 additions & 0 deletions src/LitJson/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,17 @@ public void Write (double number)
context.ExpectingValue = false;
}

public void Write(float number)
{
DoValidation(Condition.Value);
PutNewline();

string str = Convert.ToString(number, number_format);
Put(str);

context.ExpectingValue = false;
}

public void Write (int number)
{
DoValidation (Condition.Value);
Expand Down

0 comments on commit 46897c8

Please sign in to comment.