使用Rhino库操作小数时应用崩溃

时间:2019-06-11 15:52:20

标签: java android rhino

我正在使用Rhino Library在android studio中评估字符串。执行此操作时出现错误,小数乘以

小数点类似于3.08 * 23或45 + 3.10,请注意,如果我执行3.0 * 67,则不会崩溃

这是我的评估方法

  public static Object eval(final String str) {
        Object result;

        try {
            final String simpleAdd = str;
            Context jsCx = Context.enter();
            Context.getCurrentContext().setOptimizationLevel(-1);
            ScriptableObject scope = jsCx.initStandardObjects();
            result = jsCx.evaluateString(scope, simpleAdd , "formula", 0, null);
            Context.exit();
        }catch (Exception e){
           return 08998.097;
        }
        if(result == "Infinity"){
            return 08998.097;
        }
        return result;
    }

这是我的方法,当按下'='按钮时会发生

if(textArea.getText().toString().contains("=")){
            textArea.setText(textArea.getText().toString());
            word = result;
            if(spinner.getSelectedItem().equals("English")) {
                TextView tv = (TextView) findViewById(R.id.tv);
                tv.setText(EnglishNumberToWords.convert((long) word));
            }else if(spinner.getSelectedItem().equals("German")){
                TextView tv = (TextView) findViewById(R.id.tv);
                tv.setText(GermanNumberToWords.convert((long) word));
            }else{
                tv.setText(SpanishNumberToWords.convert((long) word));
            }
            return;

        }
        String text1 = textArea.getText().toString()


       result = (double)(AdvancedCalculator.eval(text1));
            //ToDo ssss

        if(result==08998.097){
            errorMessageText.setVisibility(View.VISIBLE);
            textArea.setText("");
            tv.setText("");
            return;
        }

            DecimalFormat decimalFormat = new DecimalFormat("0.###");
            String string = decimalFormat.format(result);
            result =  Long.parseLong(string);
            word = result;
            textArea.setText(textArea.getText().toString() + " = " + result);
            if(spinner.getSelectedItem().equals("English")) {
                TextView tv = (TextView) findViewById(R.id.tv);
                tv.setText(EnglishNumberToWords.convert((long) word));
            }else if(spinner.getSelectedItem().equals("German")){
                TextView tv = (TextView) findViewById(R.id.tv);
                tv.setText(GermanNumberToWords.convert((long) word));
            }else{
                tv.setText(SpanishNumberToWords.convert((long) word));
            }

每当我尝试操作小数位时,它都会崩溃,但在其他情况下却可以正常工作,这意味着当我不使用小数时(末尾带有'.0'除外)

0 个答案:

没有答案