Skip to content

Commit 75f4855

Browse files
committed
fix: disable simple formatting for negative values
1 parent 5a29e35 commit 75f4855

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

src/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<div style="border: 1px solid red; display: inline-block">
4141
<!-- <ve-progress :progress="progress" animation="rs 2000 2000" :legend-formatter="customFormatter">
4242
</ve-progress>-->
43-
<ve-progress :progress="progress" animation="default 2500 1000" legend="0001239,5465"></ve-progress>
43+
<ve-progress :progress="progress" animation="default 2500 1000" :legend="-123"></ve-progress>
4444
</div>
4545
</div>
4646
</div>

src/components/Counter.vue

+3-7
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default {
5555
return this.value.toString().includes(",") ? "," : ".";
5656
},
5757
formattedValue() {
58-
if (isString(this.value)) {
58+
if (isString(this.value) && !this.value.includes("-")) {
5959
let [preFormat] = this.value.toString().replace(/\s/g, "").split(this.delimiter);
6060
preFormat = [...preFormat].fill("0").join("");
6161
const [pre, post] = this.currentValue
@@ -64,7 +64,7 @@ export default {
6464
.split(this.delimiter);
6565
return `${preFormat.slice(pre.length)}${pre}${post ? this.delimiter + post : ""}`;
6666
}
67-
return this.currentValue.toFixed(this.countDecimals()).replace(".", this.delimiter);
67+
return this.currentValue.toFixed(this.decimalsCount).replace(".", this.delimiter);
6868
},
6969
delay() {
7070
return this.animation.delay;
@@ -77,7 +77,7 @@ export default {
7777
},
7878
decimalsCount() {
7979
if (!isString(this.value) && this.value % 1 === 0) return 0;
80-
return this.value.toString().replace(/\s/g, "").split(this.delimiter)[1].length;
80+
return (this.value.toString().replace(/\s/g, "").split(this.delimiter)[1] || "").length;
8181
},
8282
counterProps() {
8383
return {
@@ -98,10 +98,6 @@ export default {
9898
},
9999
},
100100
methods: {
101-
countDecimals() {
102-
if (this.value % 1 === 0) return 0;
103-
return this.value.toString().replace(/\s/g, "").split(this.delimiter)[1].length;
104-
},
105101
count(timeStamp) {
106102
if (!this.startTime) {
107103
this.startTime = timeStamp;

tests/unit/counter.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ describe("[ Counter.vue ]", () => {
5151
{
5252
legend: 56.34,
5353
count: 2,
54-
start: "0.00",
54+
start: "00.00",
5555
},
5656
{
5757
legend: "25,564",
5858
count: 3,
59-
start: "0,000",
59+
start: "00,000",
6060
},
6161
{
6262
legend: "-30,5",
@@ -77,7 +77,7 @@ describe("[ Counter.vue ]", () => {
7777
const counterWrapper = wrapper.findComponent(Counter);
7878

7979
it("counts the decimals correctly", () => {
80-
expect(counterWrapper.vm.countDecimals()).to.equal(count);
80+
expect(counterWrapper.vm.decimalsCount).to.equal(count);
8181
});
8282

8383
it("renders the start value with the correct number of decimals places", () => {

0 commit comments

Comments
 (0)