All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.TKnudsen.ComplexDataObject.model.tools.StringUtils Maven / Gradle / Ivy

Go to download

A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.

The newest version!
package com.github.TKnudsen.ComplexDataObject.model.tools;

/**
 * 

* Title: StringUtils *

* *

* Description: little helpers when working with String. *

* *

* Copyright: Copyright (c) 2017 *

* * @author Juergen Bernard * @version 1.02 */ public class StringUtils { public static void main(String[] args) { double value = 66.3363456; System.out.println(value); String trunc = StringUtils.truncateDouble(value, 3); System.out.println(trunc); } public static String truncateDouble(double value, int decimals) { if (decimals < 0) return null; String result = (new Double(value)).toString(); int dot = result.lastIndexOf("."); int length = result.length(); result = result.substring(0, (int) (Math.min(dot + 1 + decimals, length))); return result; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy