aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorversecafe <147033096+versecafe@users.noreply.github.com>2024-09-03 08:54:02 -0500
committerGitHub <noreply@github.com>2024-09-03 14:54:02 +0100
commitee334747949c6696a0128d1ce709078ecc564598 (patch)
tree6099b3f73f4d0b371ee2046ee3288d3400cd54a7 /test
parenta349b6273717d42c232079b0bfcf5002d10e10d3 (diff)
downloadgleam_stdlib-ee334747949c6696a0128d1ce709078ecc564598.tar.gz
gleam_stdlib-ee334747949c6696a0128d1ce709078ecc564598.zip
Add `to_precision` to `gleam/float` (#668)
Diffstat (limited to 'test')
-rw-r--r--test/gleam/float_test.gleam26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/gleam/float_test.gleam b/test/gleam/float_test.gleam
index 4c49f69..6a737e7 100644
--- a/test/gleam/float_test.gleam
+++ b/test/gleam/float_test.gleam
@@ -213,6 +213,32 @@ pub fn truncate_test() {
|> should.equal(-7)
}
+pub fn to_precision_test() {
+ float.to_precision(2.43434348473, 2)
+ |> should.equal(2.43)
+
+ float.to_precision(2.43534348473, 2)
+ |> should.equal(2.44)
+
+ float.to_precision(-2.43534348473, 2)
+ |> should.equal(-2.44)
+
+ float.to_precision(547_890.453444, -3)
+ |> should.equal(548_000.0)
+
+ float.to_precision(547_490.453444, -3)
+ |> should.equal(547_000.0)
+
+ float.to_precision(-547_490.453444, -3)
+ |> should.equal(-547_000.0)
+
+ float.to_precision(435.3224, 0)
+ |> should.equal(435.0)
+
+ float.to_precision(435.3224, -0)
+ |> should.equal(435.0)
+}
+
pub fn min_test() {
float.min(0.0, 0.0)
|> should.equal(0.0)