Skip to content

Conversation

@zeionara
Copy link

@zeionara zeionara commented Jan 9, 2023

Closes #279

In current version all doubles are encoded in a scientific notation:

import Yams

print(try Yams.dump(object: 6.85)))

produces:

6.85e+0

The proposed change is to add a static option to Emitter.Options class, so it can be used as follows:

import Yams

Emitter.Options.doubleFormatStyle = .decimal
print(try Yams.dump(object: 6.85)))

which produces the expected result:

 6.85

YAMLEncoder object is also supported, as well as numbers with zero fraction part, which are not saved as integers. For example, the following code:

import Yams

Emitter.Options.doubleFormatStyle = .decimal
print(try YAMLEncoder().encode(6.0)))

generates the expected result:

6.0

@jpsim
Copy link
Owner

jpsim commented Jan 9, 2023

Very nice, thanks for the PR! I'll take a look shortly.

@jpsim
Copy link
Owner

jpsim commented Jan 9, 2023

Could you please address the failing CI jobs? Missing documentation comments and SwiftLint rule violations. Also CMake updates.

public var mappingStyle: Node.Mapping.Style = .any

/// Set the style for formatting doubles
public static var doubleFormatStyle: NumberFormatStyle = .scientific
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A static var is not compatible with Swift 6 language mode. If we refactor this as an instance variable we can revitalize this PR.

Copy link
Collaborator

@lynchsft lynchsft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A static var is not compatible with Swift 6 language mode. If we refactor this as an instance variable we can revitalize this PR.

@wojciech-kulik
Copy link

Any chance to revive this PR?

Copy link
Collaborator

@lynchsft lynchsft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comment dated Feb 24.

@wojciech-kulik
Copy link

wojciech-kulik commented Apr 2, 2025

Oh, my mistake, I looked at the previous comment dated Jan 2023 and somehow assumed the next one from Feb was also from 2023 :D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Doubles end up in exponential notation

4 participants