Skip to content
Snippets Groups Projects
Unverified Commit 0d558f5a authored by meskio's avatar meskio :tent:
Browse files

Calculate negative prices properly

Cents should be negative as well.
parent faba59b3
Branches
Tags
No related merge requests found
......@@ -2,6 +2,12 @@ import React, { useState } from "react";
import { Form } from "react-bootstrap";
function str2price(str) {
let negative = false;
if (str[0] === "-") {
str = str.substring(1);
negative = true;
}
let value = str.split(",");
let cents = 0;
......@@ -27,7 +33,11 @@ function str2price(str) {
}
}
return parseInt(value[0]) * 100 + cents;
let price = parseInt(value[0]) * 100 + cents;
if (negative) {
price = -price;
}
return price;
}
function price2str(price) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment