private void decToFp() { if (calculator.getDisplayText().length() == 0) return; String result = ""; try { Double displayNumber = Double.parseDouble(calculator.getDisplayText()); if ((displayNumber > 944.44444) || (displayNumber < -944.44444)) { throw (new IllegalArgumentException()); } result = Utils.hexString(Utils.decToFp(displayNumber)); } catch (NumberFormatException e) { result = "Formato de numero inválido"; calculator.setErrorMode(); } catch (IllegalArgumentException Exception) { result = "Número fuera de rango"; calculator.setErrorMode(); } catch (LostPrecisionException e) { result = Utils.hexString(e.getNumber()); calculator.showPrecisionLostDialog(); } finally { calculator.setDisplayText(result); } }
private void fpToDec() { if (calculator.getDisplayText().length() == 0) return; try { Integer displayNumber = Integer.valueOf(calculator.getDisplayText(), 16); Double converted = Utils.fpToDec(displayNumber); if ((displayNumber > 944.44444) || (displayNumber < -944.44444)) { throw (new IllegalArgumentException()); } calculator.setDisplayText(converted.toString()); } catch (NumberFormatException e) { calculator.setDisplayText("Formato de numero invalido"); calculator.setErrorMode(); } catch (IllegalArgumentException e) { calculator.setDisplayText("Numero fuera de rango"); calculator.setErrorMode(); } }