Skip to content

Commit 97ed0dc

Browse files
committed
simplify noExponent function
1 parent 17a15aa commit 97ed0dc

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

src/charts/common/bar/Helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export default class Helpers {
138138

139139
x =
140140
w.globals.padHorizontal +
141-
(xDivision - barWidth * this.barCtx.seriesLen) / 2
141+
Utils.noExponents(xDivision - barWidth * this.barCtx.seriesLen) / 2
142142
}
143143

144144
w.globals.barHeight = barHeight

src/utils/Utils.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,12 @@ class Utils {
148148
return (Math.random() + 1).toString(36).substring(4)
149149
}
150150

151-
static noExponents(val) {
152-
let data = String(val).split(/[eE]/)
153-
if (data.length === 1) return data[0]
154-
155-
let z = '',
156-
sign = val < 0 ? '-' : '',
157-
str = data[0].replace('.', ''),
158-
mag = Number(data[1]) + 1
159-
160-
if (mag < 0) {
161-
z = sign + '0.'
162-
while (mag++) z += '0'
163-
return z + str.replace(/^-/, '')
151+
static noExponents(num) {
152+
// Check if the number contains 'e' (exponential notation)
153+
if (num.toString().includes('e')) {
154+
return Math.round(num) // Round the number
164155
}
165-
mag -= str.length
166-
while (mag--) z += '0'
167-
return str + z
156+
return num // Return as-is if no exponential notation
168157
}
169158

170159
static elementExists(element) {

0 commit comments

Comments
 (0)