Tags down


parse float in java with trailing junk

By : Arjay Almocera
Date : August 02 2020, 02:00 AM
To fix this issue The documentation for Double.valueOf(String) actually includes a regex that you can use to check whether a string is a double.
Here it is, without the comments:
code :
final String Digits     = "(\\p{Digit}+)";
final String HexDigits  = "(\\p{XDigit}+)";
final String Exp        = "[eE][+-]?"+Digits;
final String fpRegex    =
                "[+-]?(" +
                "Infinity|" +
                "((" +
                "(0[xX]" + HexDigits + "(\\.)?)|" +
                "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
                ")[pP][+-]?" + Digits + "))" +
                "[fFdD]?))" +
Matcher m = Pattern.compile(fpRegex).matcher(input);
if (m.find()) {
    String doublePartOnly = m.group();

Share : facebook icon twitter icon

Remove junk trailing xml from an inputstream

By : user3334413
Date : March 29 2020, 07:55 AM
wish help you to fix your issue
I'm about to create a class that will take my InputStream, read through it until I find the junk, break, then take what I just wrote to, convert it back into an InputStream and pass it along like nothing happened. But I'm worried that it'll be grossly inefficient, have bugs I shouldn't have to deal with (e.g. breaking on binary values such as embedded images) and hopefully unnecessary.
code :
class WebStream extends FilterInputStream {

    byte[] buff = new byte[1024];
    int offset = 0, length = 0;

    public WebStream(InputStream i) {

    public boolean markSupported() {
        return false;

    public int read() throws IOException {
        if (offset == length)
        if (length == -1)
            return -1;// eof
        return buff[offset++];

    public int read(byte[] b, int off, int len) throws IOException {
        if (offset == length)
        if (length == -1)
            return -1;// eof

        int cop = length - offset;
        if (len < cop)
            cop = len;
        System.arraycopy(buff, offset, b, off, cop);
        offset += cop;
        return cop;

    private void readNextChunk() throws IOException {
        if (offset <= length) {
            System.arraycopy(buff, offset, buff, 0, length - offset);
            length -= offset;
            offset = 0;
        int read = in.read(buff, length, buff.length - length);
        if (read < 0 && length <= 0) {
            length = -1;
            offset = 0;

        // note that this is assuming ascii compatible
        // anything like utf16 or utf32 will break here
        for (int i = length; i < read + length; i += 16) {
            if (buff[i] == 0x04) {
                while (buff[--i] == 0x04)
                    ;// find beginning of delim block
                length = i;
                read = 0;


How can I make a DateTimeFormatter that accepts trailing junk?

By : user3311830
Date : March 29 2020, 07:55 AM
To fix this issue Use the parse() method that takes a ParsePosition, as that one doesn't fail when it doesn't read the entire text:
code :
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");

TemporalAccessor parse = formatter.parse("20140314 some extra text", new ParsePosition(0));

How can I convert a string to a float without losing trailing 0s in Java?

By : SandeepLoka
Date : March 29 2020, 07:55 AM
seems to work fine Usually when converting a string to a float you lose decimal trailing 0s. For specific reasons I need to keep exactly the number of trailing 0s I have in the string. The code I currently use for this is , Try this:
code :
float res = Float.parseFloat(avgStr);
System.out.printf("%.2f", res);
String st = "12.0000";
float dd = Float.valueOf(st);
int len = st.substring(st.indexOf(".") + 1, st.length()).length();
System.out.printf("%." + len + "f", dd);

Java keep trailing 0 in float operations

By : Lakkeri
Date : March 29 2020, 07:55 AM
Hope that helps You are confusing a number value and its formatting. It is not possible to actually store 1.80 as a float, however it is possible to display the number as a formatted String which forces two decimal places. Your options are:

Java float to string conversion with trailing zeros

By : Abhi
Date : March 29 2020, 07:55 AM
I wish this helpful for you If you want it to store the whole number, why don't you just use a String?
I guess if you are getting "1.10" from somewhere, you are getting it as a String (or you would be getting just a "1.1").
Related Posts Related Posts :
  • IMB PCF agent returns error while inquiring channel status
  • Java EE 7 batch API (JSR-352): it's possible to stop a single step and not all the job?
  • Java multithread example - is object shared or not
  • Why String's replaceAll() method come at high performance cost at the first time and faster at the next time?
  • Lua script coverts empty array to object
  • Doesn't Access to external storage in API-29
  • How to add a button to the Android system navigation bar?
  • If inside for-each-loop to Stream
  • Shift array to the right by one slot
  • How to setup a Java development environment for Z3
  • how to make notify() works properly with wait()
  • IllegalFormatConversionException d != java.lang.Integer when trying to printf date?
  • Duplicate logic in backend and frontend with Domain Driven Design
  • How would I randomize an int[][]?
  • StringDate to Date coming in different Time in SimpleDateFormat in java
  • Get content uri from file path in android for video
  • function param issue in Scala 11, works in Scala 12 using resilience4j
  • Android unit testing : calling a method from fragment which uses context
  • How to remove E notation from Double value
  • Check if input is any of the values in an array
  • DateTimeParseException - could not be parsed at index 0
  • How to make a Java HTTP async request?
  • Make Javafx/Scenebuilder recognize tagged fields and methods when splitting the MainController into multiple files?
  • Why does this time fail to be parsed by DateTimeFormatter.ofPattern()?
  • Java - Merge objects of list given a condition
  • How to know if arraylist contains value in property of object?
  • Java modelling class if objects have same properties but they are fundamentally different
  • False Positive and False Negative
  • Java UnknownFormatConversionException = ','
  • Apache POI recording only 1 row in the spreadsheet
  • Getting Constructor from Java Class that would be called for argument types, not requiring exact argument & paramete
  • @JsonIgnore with Conditions
  • Does synchronizing on the static field that you are modifying make your code thread safe?
  • Compiler errors while trying to make a pop up
  • Trying to take two timestamps, subtract them, convert the difference to seconds and store in an int variable
  • How can I use Optionals instead of nested if statement?
  • How do I compare values in parallel arrays to eliminate duplicates?
  • make a method which returns the number of one digit numbers in an array
  • Does calling multiple times save() method of hibernate with same object insert new record in DB?
  • Single Number solving by Haspmap, return always be a "@"
  • What do you do about the JLabel classes? It says, "JLabel not a statement" for the error
  • Functional Interface call for a new Instance
  • When I tried to add ArrayList into ArrayList second ArrayList is repeating
  • How can I print the longest word from a user defined list?
  • enabling authentication in ignite
  • Providing OSGi Service Without Implementing Interface
  • Read manifest from JAR with gradle
  • Create one element Set the same way (if applicable) as create single element list
  • pass by reference an integer in java
  • how to generate the POI excel file in a specific location?
  • Issue trying to create a Bubble Sort using ArrayList<Integer>
  • How can I avoid typechecking in this situation
  • How to create a map<k,v> between first and last nested object using Java streams?
  • First time writing junit: Need suggestions
  • what is the best solution to split in chunk monthly given two dates startTime and EndTime in Java?
  • View Binding causes "The specified child already has a parent"
  • How to convert color from ColorPicker to String value in javaFX
  • Spring test integration not run how I deal with this error?
  • Java 8 Streams : Count the occurrence of elements(List<String> list1) from list of text data(List<String> li
  • What is the difference between static and protected in java?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org