converter/src/app/converter/dectohexconverter.ts

20 lines
427 B
TypeScript
Raw Normal View History

2017-04-15 19:04:49 +02:00
import {Converter} from './converter';
export class DecToHexConverter implements Converter {
getDisplayname(): string {
2017-04-15 19:04:49 +02:00
return 'Convert decimal to hexadecimal';
}
getId(): string {
2017-04-15 19:04:49 +02:00
return 'dectohex';
}
convert(input: string): string {
2017-04-15 19:07:34 +02:00
const n: number = parseInt(input, 10);
if (isNaN(n)) {
2017-04-15 19:04:49 +02:00
throw new Error('The input seems not to be a valid integer.');
}
return n.toString(16);
}
}