Replaced toFixed with Math.round

This commit is contained in:
octopusGarden 2022-11-04 15:28:29 -04:00
parent ddac01b1f4
commit 07d6d7683f
2 changed files with 9 additions and 11 deletions

View File

@ -1,17 +1,15 @@
const ftoc = function(fnum) {
//formula to convert f to c
let cnum = (fnum - 32) * 5 % 9;
let cnum = (fnum - 32) * 5 / 9;
//round to one decimal
let roundCnum = parseInt(cnum.toFixed(1));
return roundCnum;
return Math.round(cnum * 10) / 10;
};
const ctof = function() {
const ctof = function(cnum) {
//formula to convert c to f
let fnum = (cnum * 9/5) + 32;
//round to one decimal
let roundFnum = parseInt(fnum.toFixed(0));
return roundFnum;
return Math.round(fnum * 10) / 10;
};
// Do not edit below this line

View File

@ -4,22 +4,22 @@ describe('ftoc', () => {
test('works', () => {
expect(ftoc(32)).toEqual(0);
});
test.skip('rounds to 1 decimal', () => {
test('rounds to 1 decimal', () => {
expect(ftoc(100)).toEqual(37.8);
});
test.skip('works with negatives', () => {
test('works with negatives', () => {
expect(ftoc(-100)).toEqual(-73.3);
});
});
describe('ctof', () => {
test.skip('works', () => {
test('works', () => {
expect(ctof(0)).toEqual(32);
});
test.skip('rounds to 1 decimal', () => {
test('rounds to 1 decimal', () => {
expect(ctof(73.2)).toEqual(163.8);
});
test.skip('works with negatives', () => {
test('works with negatives', () => {
expect(ctof(-10)).toEqual(14);
});
});