Here you can find the source of minusxx(String str11, String str22)
private static String minusxx(String str11, String str22)
//package com.java2s; //License from project: Apache License public class Main { private static String minusxx(String str11, String str22) { int index1 = str11.indexOf("."); int len1 = str11.length() - 1 - index1; int index2 = str22.indexOf("."); int len2 = str22.length() - 1 - index2; String str1 = str11.replace(".", ""); String str2 = str22.replace(".", ""); char[] ch1 = new char[str1.length()]; reverse(str1, ch1);//w w w . j av a 2 s. c om char[] ch2 = new char[str2.length()]; reverse(str2, ch2); int[] res = new int[str1.length() > str2.length() ? str1.length() + 1 : str2.length() + 1]; StringBuilder sb = new StringBuilder(); for (int i = 0; i < ch1.length; i++) { res[i] = (ch1[i] - '0') - (ch2[i] - '0'); if (res[i] < 0) { res[i] = res[i] + 10; ch1[i + 1] = (char) ((ch1[i + 1] - '0') - ('1' - '0') + 48); } sb.append(res[i]); } String result = sb.reverse().toString(); int indexx = 0; if (str11.contains(".") || str22.contains(".")) { if (len1 >= len2) { indexx = result.length() - len1; } else { indexx = result.length() - len2; } StringBuilder ss = new StringBuilder(result); ss.insert(indexx, "."); result = ss.toString(); } int index = -1; for (int i = 0; i < result.length(); i++) { if (result.charAt(0) == '0') { if (result.charAt(i) == '0' && result.charAt(i + 1) != '0') { index = i; break; } } } if (index != -1) { result = result.substring(index + 1); } return result; } private static void reverse(String str1, char[] ch1) { for (int i = str1.length() - 1; i >= 0; i--) { ch1[i] = str1.charAt(str1.length() - 1 - i); } } }