Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserve formatting of floats in edge cases #65

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions unityparser/dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ def represent_str(dumper, instance):
return dumper.represent_scalar('tag:yaml.org,2002:str', instance, style=style)


def represent_float(dumper, instance):
float_str = str(instance)
if 'e' in float_str:
float_str = format(instance, '.17f').rstrip('0')
return dumper.represent_scalar('tag:yaml.org,2002:float', float_str)


Representer.add_multi_representer(UnityClass, represent_unity_class)
Representer.add_representer(OrderedFlowDict, represent_ordered_flow_dict)
Representer.add_representer(type(None), represent_none)
Representer.add_representer(uniqstr, represent_str)
Representer.add_representer(float, represent_float)
13 changes: 13 additions & 0 deletions unityparser/tests/fixtures/MultiDoc.asset
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ MonoBehaviour:
fullBlinks: 3
interpolation: 4
pieceType: 2
f1: 0.000001
f2: 0.0000001
f3: 0.00000001
f4: 0.000000001
f5: -0.7071068
f6: 0.7071068
f7: 0.00000011920929
f8: 0.231
f9: 0.0423
f10: 1e+10
f11: 1e+28
f12: 1e-11
f13: 1.1111111e-11
--- !u!212 &212685313502090504
SpriteRenderer:
m_ObjectHideFlags: 1
Expand Down
Loading