I have found many resources talking about base conversion algorithms and using built in Javascript functions to convert decimal to binary or hex, however I can't find any resources on how to convert to any fractional bases like base 3/2 for instance. The sesquinary number system is quite interesting and I want to be able to use it, but I can't find any way to convert to it from Decimal.
The sesquinary system is as follows: 1, 2, 20, 21, 22, 210, 211, 212, 2100, 2101, etc.
I can't get any reliable way to convert to it. Here is the code I have so far:
function decimalToBase(number, base) {
let digitArray = [];
let quotient;
let remainder;
for (let i = 0; i < 16; i++) {
quotient = Math.floor(number / base);
remainder = number % base;
digitArray.unshift(remainder);
number = quotient;
if (quotient == 0){
break;
}
}
console.log(digitArray)
}
It works for whole bases under 10, but if I enter a fractional base like 3/2, then I get a result with decimals:
[1, 0.5, 1, 0] // When It should be: [2, 1, 0]
Any help would be greatly appreciated.