Skip to content

Commit

Permalink
Remove leading zeros correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
uellenberg committed May 3, 2021
1 parent 96dc15a commit 3117241
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Num.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class Num {
by the digits so far), then the loop is stopped early.
*/
let digit = this._number;
const digitLog = Math.ceil(Math.log(digit)/Math.log(this._base)) + (digit % this._base === 0 ? 1 : 0);
let digitLog = Math.ceil(Math.log(digit)/Math.log(this._base)) + (digit % this._base === 0 ? 1 : 0);

let digits: string[] = [];
let toAdd: string[] = [];
Expand All @@ -142,7 +142,11 @@ export class Num {

const digitStr = NumberToDigit(number);

if(digitStr === "0" && digits.length < 1) continue;
if(digitStr === "0" && digits.length < 1) {
//This is just to make sure the decimal symbol is placed in the correct location.
digitLog--;
continue;
}

if(digitStr !== "0") {
digits.push(...toAdd, digitStr);
Expand Down

0 comments on commit 3117241

Please sign in to comment.