converter/src/app/converter/hextodecconverter.ts

20 lines
438 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 {
const 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);
}
}