Skip to content

Commit 4c0f8e9

Browse files
Merge pull request #170 from gabriel-samfira/prioritize-decimal
Use decimal as first option when parsing floats
2 parents ff6fce6 + 62d6f91 commit 4c0f8e9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Tests/powershell-yaml.Tests.ps1

+9
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ bools:
703703
bigInt: 99999999999999999999999999999999999
704704
int32: 2147483647
705705
int64: 9223372036854775807
706+
decimal: 3.10
706707
'@
707708
}
708709

@@ -711,11 +712,19 @@ int64: 9223372036854775807
711712
$result.bigInt | Should -BeOfType System.Numerics.BigInteger
712713
}
713714

715+
It "Should round-trip decimals with trailing 0" {
716+
$result = ConvertFrom-Yaml -Yaml $value
717+
$result.decimal | Should -Be ([decimal]3.10)
718+
719+
ConvertTo-Yaml $result["decimal"] | Should -Be "3.10$([Environment]::NewLine)"
720+
}
721+
714722
It 'Should be of proper type and value' {
715723
$result = ConvertFrom-Yaml -Yaml $value
716724
$result.bigInt | Should -Be ([System.Numerics.BigInteger]::Parse("99999999999999999999999999999999999"))
717725
$result.int32 | Should -Be ([int32]2147483647)
718726
$result.int64 | Should -Be ([int64]9223372036854775807)
727+
$result.decimal | Should -Be ([decimal]3.10)
719728
}
720729
}
721730

powershell-yaml.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function Convert-ValueToProperType {
218218
}
219219
return $parsedValue
220220
}
221-
$types = @([double], [decimal])
221+
$types = @([decimal], [double])
222222
foreach($i in $types){
223223
$parsedValue = New-Object -TypeName $i.FullName
224224
$result = $i::TryParse($Node, [Globalization.NumberStyles]::Float, [Globalization.CultureInfo]::InvariantCulture, [ref]$parsedValue)

0 commit comments

Comments
 (0)