List of usage examples for java.math BigDecimal toString
@Override
public String toString()
From source file:Main.java
public static void main(String[] args) { MathContext mc = new MathContext(3); // 3 precision BigDecimal bg = new BigDecimal("1234E4", mc); System.out.println(bg.toString()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int decimalPlaces = 2; BigDecimal bd = new BigDecimal("123456789.0123456890"); bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_DOWN); String string = bd.toString(); }
From source file:org.kuali.student.git.importer.ReportBlobSizePerBranch.java
/** * @param args//from w w w . j a va 2s . c o m */ public static void main(String[] args) { if (args.length != 3 && args.length != 4) { System.err.println( "USAGE: <git repository> <bare: 0 or 1> <output file name>[<refs prefix: default to refs/heads >]"); System.exit(-1); } String gitRepositoryPath = args[0]; String bareString = args[1].trim(); boolean bare = false; if (bareString.equals("1")) bare = true; String refPrefix = Constants.R_HEADS; String outputFileName = args[2].trim(); if (args.length == 4) refPrefix = args[3].trim(); try { PrintWriter outputWriter = new PrintWriter(outputFileName); Repository repo = GitRepositoryUtils.buildFileRepository(new File(gitRepositoryPath).getAbsoluteFile(), false, bare); Map<String, Ref> branchHeads = repo.getRefDatabase().getRefs(refPrefix); ObjectReader objectReader = repo.newObjectReader(); RevWalk rw = new RevWalk(objectReader); TreeWalk tw = new TreeWalk(objectReader); tw.setRecursive(true); String header = String.format( "Branch Name :: Total Commits in Graph :: Total Blob Size in Bytes :: Total Blob Size in Mega Bytes :: Total Blob Size in Giga Bytes"); System.out.println(header); outputWriter.println(header); for (Map.Entry<String, Ref> entry : branchHeads.entrySet()) { String branchName = entry.getKey(); Ref branchRef = entry.getValue(); Set<ObjectId> blobIds = new HashSet<>(); RevCommit commit = rw.parseCommit(branchRef.getObjectId()); RevWalk commitHistoryWalk = new RevWalk(objectReader); commitHistoryWalk.markStart(commit); processCommit(commit, tw, blobIds); int totalReachableCommits = 0; while ((commit = commitHistoryWalk.next()) != null) { processCommit(commit, tw, blobIds); totalReachableCommits++; } long totalSize = 0L; AsyncObjectSizeQueue<ObjectId> sq = objectReader.getObjectSize(blobIds, true); while (sq.next()) totalSize += sq.getSize(); BigDecimal totalCounter = new BigDecimal(totalSize); String output = String.format("%s::%d::%s::%s::%s", branchName, totalReachableCommits, totalCounter.toString(), getMB(totalCounter).toString(), getGB(totalCounter).toString()); System.out.println(output); outputWriter.println(output); commitHistoryWalk.release(); } tw.release(); rw.release(); objectReader.release(); outputWriter.close(); } catch (Exception e) { log.error("unexpected exception", e); } }
From source file:org.polymap.kaps.ui.form.NHK2010BewertungFormEditorPage.java
public static void main(String[] args) { System.out.println(Math.floor(9.5d + 0.5d)); System.out.println(Math.floor(9.4d + 0.55d)); System.out.println(Math.floor(9.49d + 0.55d)); System.out.println(Math.floor(9.8d + 0.5d)); System.out.println(Math.round(9.5d)); System.out.println(Math.round(9.4d)); System.out.println(Math.round((9.49d * 100) / 100)); System.out.println(Math.round(9.8d)); System.out.println(new DecimalFormat("###").format(9.49d)); BigDecimal bd = new BigDecimal(9.49d); bd = bd.round(MathContext.UNLIMITED); System.out.println(bd.toString()); }
From source file:Main.java
public static String getBigDecimal(double time) { BigDecimal big = new BigDecimal(time); return big.toString(); }
From source file:org.cryptomath.util.NumberUtil.java
public static String absorbFloats(BigDecimal value) { return NumberUtil.absorbFloats(value.toString()); }
From source file:org.cryptomath.util.NumberUtil.java
private static void check(final BigDecimal bigDecimal, final String string) { if (!bigDecimal.toString().equals(string)) { throw new IllegalStateException("not equal: " + bigDecimal + " and " + string); }/* w w w .ja va2 s . c o m*/ }
From source file:Main.java
public static int convertToInteger(String data) { BigDecimal num = new BigDecimal(data).setScale(NUM_AFTER_COM, BigDecimal.ROUND_HALF_UP); String res = num.toString().replace(".", ""); return Integer.valueOf(res); }
From source file:RSMetaData.java
public static void getData(ResultSet rs, int type, int colIdx) throws SQLException { switch (type) { case java.sql.Types.CHAR: case java.sql.Types.VARCHAR: System.out.println(rs.getString(colIdx)); break;// www . j av a 2s. co m case java.sql.Types.INTEGER: int i = rs.getInt(colIdx); System.out.println(i); break; case java.sql.Types.NUMERIC: BigDecimal bd = rs.getBigDecimal(colIdx); System.out.println(bd.toString()); break; case java.sql.Types.TIMESTAMP: case java.sql.Types.DATE: java.sql.Date d = rs.getDate(colIdx); System.out.println(d.toString()); break; } }
From source file:Main.java
public static String f2Bi(float d) { BigDecimal bigDecimal = new BigDecimal(d); bigDecimal = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP); return bigDecimal.toString(); }