converter/src/app/converter/hextodecconverter.ts

20 lines
435 B
TypeScript

import {Converter} from "./converter";
export class HexToDecConverter implements Converter {
getDisplayname(): string {
return "Convert hexadecimal to decimal";
}
getId(): string {
return "hextodec";
}
convert(input: string): string {
let n: number = parseInt(input, 16);
if (isNaN(n)) {
throw new Error("The input seems not to be a valid hexadecimal number.")
}
return n.toString(10);
}
}