Skip to content

Commit

Permalink
Replace floor/ceil decimal with Round (#788)
Browse files Browse the repository at this point in the history
* Replace floor/ceil decimal with Round

* [-] forgotten comment

---------

Co-authored-by: Marek Vigaš <[email protected]>
  • Loading branch information
Ormi and MarekVigas authored Oct 7, 2023
1 parent 3546c2c commit afa2593
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 63 deletions.
46 changes: 0 additions & 46 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
floorDecimal,
ceilDecimal,
parseStreetAndNumber,
encodeUnicodeCharacters,
getStreetNumber,
Expand Down Expand Up @@ -318,50 +316,6 @@ describe('utils', () => {
})
})

describe('#floorDecimal', () => {
describe('for valid values', () => {
const validInputs = [
{
input: new Decimal(916.487),
output: new Decimal(916.48),
},
{
input: new Decimal(99.654),
output: new Decimal(99.65),
},
]

validInputs.forEach(({ input, output }) => {
it(`should floor "${input}" to "${output}"`, () => {
expect(floorDecimal(input).equals(output)).toBeTruthy()
})
})
})
})
describe('#ceilDecimal', () => {
describe('for valid values', () => {
const validInputs = [
{
input: new Decimal(2864.094),
output: new Decimal(2864.1),
},
{
input: new Decimal(2864.444),
output: new Decimal(2864.45),
},
{
input: new Decimal(2864.099),
output: new Decimal(2864.1),
},
]

validInputs.forEach(({ input, output }) => {
it(`should floor "${input}" to "${output}"`, () => {
expect(ceilDecimal(input).toNumber()).toEqual(output.toNumber())
})
})
})
})
describe('#parseStreetAndNumber', () => {
const scenarios = [
{ input: ' A. Bernoláka 6 ', output: ['A. Bernoláka', '6'] },
Expand Down
6 changes: 2 additions & 4 deletions src/lib/calculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { ChildInput, TaxFormUserInput } from '../types/TaxFormUserInput'
import { Child, TaxForm } from '../types/TaxForm'
import {
getRodneCisloAgeAtYearAndMonth,
floorDecimal,
parseInputNumber,
percentage,
ceilDecimal,
sum,
round,
} from './utils'
Expand Down Expand Up @@ -231,7 +229,7 @@ export function calculate(input: TaxFormUserInput): TaxForm {
return new Decimal(0)
}
if (this.r072_pred_znizenim.gt(MAX_ZAKLAD_DANE)) {
return ceilDecimal(
return round(
Decimal.max(
0,
new Decimal(ZIVOTNE_MINIMUM_44_NASOBOK).minus(
Expand Down Expand Up @@ -303,7 +301,7 @@ export function calculate(input: TaxFormUserInput): TaxForm {
//
// ak je r. 40 viac ako je r. 77, potom na r. 78 uvediete rozdiel r. 40 - . 77
get r078_zaklad_dane_zo_zamestnania() {
return floorDecimal(
return round(
Decimal.max(this.r038.minus(this.r077_nezdanitelna_cast), 0),
)
},
Expand Down
13 changes: 0 additions & 13 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,6 @@ export interface ParsedName {
title: string
}

/**
* @deprecated The method should not be used see issue https://github.com/slovensko-digital/priznanie-digital/issues/773
*/
export const floorDecimal = (decimal: Decimal) => {
return decimal.toDecimalPlaces(2, Decimal.ROUND_FLOOR)
}
/**
* @deprecated The method should not be used see issue https://github.com/slovensko-digital/priznanie-digital/issues/773
*/
export const ceilDecimal = (decimal: Decimal) => {
return decimal.toDecimalPlaces(2, Decimal.ROUND_CEIL)
}

export const round = (decimal: Decimal): Decimal => {
return decimal.toDecimalPlaces(2, Decimal.ROUND_HALF_UP)
}
Expand Down

0 comments on commit afa2593

Please sign in to comment.