Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
37e8467e
Commit
37e8467e
authored
10 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
couple fixes for zero comparison.
parent
9ae7c238
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/util.clj
+1
-1
1 addition, 1 deletion
src/metabase/util.clj
test/metabase/test_util.clj
+13
-3
13 additions, 3 deletions
test/metabase/test_util.clj
with
14 additions
and
4 deletions
src/metabase/util.clj
+
1
−
1
View file @
37e8467e
...
...
@@ -122,7 +122,7 @@
(
let
[
decimal-type?
#
(
or
(
float?
%
)
(
decimal?
%
))]
(
cond
;; looks like this is a decimal number, format with precision of 2
(
and
(
decimal-type?
number
)
(
not
=
0
(
mod
number
1
)))
(
format
"%,.2f"
number
)
(
and
(
decimal-type?
number
)
(
not
(
zero?
(
mod
number
1
)))
)
(
format
"%,.2f"
number
)
;; this is a decimal type number with no actual decimal value, so treat it as a whole number
(
decimal-type?
number
)
(
format
"%,d"
(
long
number
))
;; otherwise this is a whole number
...
...
This diff is collapsed.
Click to expand it.
test/metabase/test_util.clj
+
13
−
3
View file @
37e8467e
...
...
@@ -48,22 +48,32 @@
;; ## tests for `(format-num)`
;; basic whole number case
(
expect
"1"
(
format-num
1
))
(
expect
"1"
(
format-num
(
float
1
)))
(
expect
"1"
(
format-num
(
double
1
)))
(
expect
"1"
(
format-num
(
bigdec
1
)))
(
expect
"1"
(
format-num
(
long
1
)))
;; make sure we correctly format down to 2 decimal places
;; note that we are expecting a round DOWN in this case
(
expect
"1.23"
(
format-num
(
float
1.23444
)))
(
expect
"1.23"
(
format-num
(
double
1.23444
)))
(
expect
"1.23"
(
format-num
(
bigdec
1.23444
)))
;; test that we always force precision of 2 on decimal places
(
expect
"1.20"
(
format-num
(
float
1.2
)))
(
expect
"1.20"
(
format-num
(
double
1.2
)))
(
expect
"1.20"
(
format-num
(
bigdec
1.2
)))
;; we can take big numbers and add in commas
(
expect
"1,234"
(
format-num
1234
))
(
expect
"1,234"
(
format-num
(
float
1234
)))
(
expect
"1,234"
(
format-num
(
double
1234
)))
(
expect
"1,234"
(
format-num
(
bigdec
1234
)))
(
expect
"1,234"
(
format-num
(
long
1234
)))
(
expect
"1,234.56"
(
format-num
(
float
1234.5678
)))
(
expect
"1,234.56"
(
format-num
(
double
1234.5678
)))
(
expect
"1,234.56"
(
format-num
(
bigdec
1234.5678
)))
;; we can handle numbers with both commas and decimal places
;; note that we expect a basic round UP here
(
expect
"1,234.57"
(
format-num
(
float
1234.5678
)))
(
expect
"1,234.57"
(
format-num
(
double
1234.5678
)))
(
expect
"1,234.57"
(
format-num
(
bigdec
1234.5678
)))
;;; ## tests for IS-URL?
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment