Skip to content

Commit

Permalink
Added decimal overload for MathJS.Math.Round (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegopego committed Jan 2, 2023
1 parent 12e9f37 commit c84b153
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/stdlib/WebSharper.MathJS/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ module Definition =
[|
BaseNumber.Type
T<float>
T<decimal>
T<int>
Unit.Type
|]
Expand All @@ -158,6 +159,7 @@ module Definition =
[|
BaseNumber.Type
T<float>
T<decimal>
T<int>
Unit.Type
|]
Expand Down
9 changes: 9 additions & 0 deletions tests/WebSharper.Tests/MathJS.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ let Tests runServerSide =
equalMsg (MathJS.Math.Add(1., 2., 3.)) 6. "MathJS.Math.Add(1., 2., 3.) = 6"
}

Test "MathJS add (decimal)" {
equalMsg (MathJS.Math.Add(1.0m, 0.1m, 2.0m, 0.2m)) 3.3m "MathJS.Math.Add(1.0m, 0.1m, 2.0m, 0.2m) = 3.3m"
}

Test "MathJS add (fraction)" {
let a = MathJS.Math.Fraction(0.1)
Expand Down Expand Up @@ -288,6 +291,12 @@ let Tests runServerSide =
equal (floor x) 18133887298m
}

Test "MathJS.Math.Round" {
let x = 18133887298.441562272235520m
equal (MathJS.Math.Round(x, 0m)) 18133887298m
equal (MathJS.Math.Round(x, 2m)) 18133887298.44m
}

Test "Decimal comparison" {
let x = 18133887298.441562272235520m
let y = 18133887298.441562272237357m
Expand Down

0 comments on commit c84b153

Please sign in to comment.