mirror of
https://github.com/linuxserver/budge.git
synced 2026-03-09 00:08:38 +08:00
attempting to better handle decimal accuracy on user input
This commit is contained in:
parent
0ed43c1bc5
commit
edce030df6
@ -62,11 +62,17 @@ export default function BudgetTableAssignedCell({ budgeted, onSubmit }) {
|
||||
const onKeyPress = e => {
|
||||
if (e.key === 'Enter') {
|
||||
try {
|
||||
const newValue = Currency.inputToDinero(mexp.eval(rowValue))
|
||||
const fixedValue = rowValue.replace(/\d+\.?\d*/g, (match, contents, offset, input) => {
|
||||
return Currency.inputToValue(match)
|
||||
})
|
||||
|
||||
const newValue = Currency.valueToDinero(mexp.eval(fixedValue))
|
||||
setRowValue(Currency.intlFormat(newValue))
|
||||
onSubmit(newValue, month)
|
||||
e.target.blur()
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,14 @@ export class Currency {
|
||||
}
|
||||
|
||||
static inputToDinero(amount) {
|
||||
return dinero({ amount: parseInt(amount * 100), currency: currencies[Currency.getCurrency()] })
|
||||
return dinero({
|
||||
amount: parseInt(`${parseFloat(amount).toFixed(2)}`.replace('.', '')),
|
||||
currency: currencies[Currency.getCurrency()],
|
||||
})
|
||||
}
|
||||
|
||||
static inputToValue(amount) {
|
||||
return dineroToValue(Currency.inputToDinero(amount))
|
||||
}
|
||||
|
||||
static intlFormat(dineroObject, locale, options = {}) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user