Replaced toFixed with Math.round
This commit is contained in:
		
							parent
							
								
									ddac01b1f4
								
							
						
					
					
						commit
						07d6d7683f
					
				|  | @ -1,17 +1,15 @@ | ||||||
| const ftoc = function(fnum) { | const ftoc = function(fnum) { | ||||||
|   //formula to convert f to c
 |   //formula to convert f to c
 | ||||||
|   let cnum = (fnum - 32) * 5 % 9; |   let cnum = (fnum - 32) * 5 / 9; | ||||||
|   //round to one decimal
 |   //round to one decimal
 | ||||||
|   let roundCnum = parseInt(cnum.toFixed(1)); |   return Math.round(cnum * 10) / 10; | ||||||
|   return roundCnum; |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const ctof = function() { | const ctof = function(cnum) { | ||||||
|   //formula to convert c to f
 |   //formula to convert c to f
 | ||||||
|   let fnum = (cnum * 9/5) + 32; |   let fnum = (cnum * 9/5) + 32; | ||||||
|   //round to one decimal
 |   //round to one decimal
 | ||||||
|   let roundFnum = parseInt(fnum.toFixed(0)); |   return Math.round(fnum * 10) / 10; | ||||||
|   return roundFnum; |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| // Do not edit below this line
 | // Do not edit below this line
 | ||||||
|  |  | ||||||
|  | @ -4,22 +4,22 @@ describe('ftoc', () => { | ||||||
|   test('works', () => { |   test('works', () => { | ||||||
|     expect(ftoc(32)).toEqual(0); |     expect(ftoc(32)).toEqual(0); | ||||||
|   }); |   }); | ||||||
|   test.skip('rounds to 1 decimal', () => { |   test('rounds to 1 decimal', () => { | ||||||
|     expect(ftoc(100)).toEqual(37.8); |     expect(ftoc(100)).toEqual(37.8); | ||||||
|   }); |   }); | ||||||
|   test.skip('works with negatives', () => { |   test('works with negatives', () => { | ||||||
|     expect(ftoc(-100)).toEqual(-73.3); |     expect(ftoc(-100)).toEqual(-73.3); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| describe('ctof', () => { | describe('ctof', () => { | ||||||
|   test.skip('works', () => { |   test('works', () => { | ||||||
|     expect(ctof(0)).toEqual(32); |     expect(ctof(0)).toEqual(32); | ||||||
|   }); |   }); | ||||||
|   test.skip('rounds to 1 decimal', () => { |   test('rounds to 1 decimal', () => { | ||||||
|     expect(ctof(73.2)).toEqual(163.8); |     expect(ctof(73.2)).toEqual(163.8); | ||||||
|   }); |   }); | ||||||
|   test.skip('works with negatives', () => { |   test('works with negatives', () => { | ||||||
|     expect(ctof(-10)).toEqual(14); |     expect(ctof(-10)).toEqual(14); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue