How to convert a String with decimals to BigDecimal and keep the decimals, in Talend Java?
Tag : java , By : user142345
Date : March 29 2020, 07:55 AM
will help you I'm creating a Job in Talend to transform data from a .csv file using some data from a database and then incorporate into another .csv file. During the transformation some calculation is needed to be performed on the values: , You can use BigDecimal BigDecimal v1 = new BigDecimal("15.25");
BigDecimal v2 = new BigDecimal("5.25");
BigDecimal v3 = new BigDecimal("1.15");
BigDecimal v123 = v1.divide(v2, MathContext.DECIMAL64).multiply(v3);
System.out.println(v123);
System.out.println(v123.setScale(2, RoundingMode.HALF_UP));
3.34047619047619075
3.34
double v1 = 15.25;
double v2 = 5.25;
double v3 = 1.15;
double v123 = v1 / v2 * v3;
System.out.println(v123);
System.out.printf("%.2f%n", v123);
3.34047619047619
3.34
3.340476190476190476190476190476191
|
How to convert decimal timestamp to date in Java with trailing decimals
Tag : java , By : Sebastian Gift
Date : March 29 2020, 07:55 AM
I hope this helps you . I have been trying to figure out how to convert a timestamp to a date but with the trailing decimals at the end, so for example: Timestamp - C50204EC EC42EE92 is equivalent to Sep 27, 2004 03:18:04.922896299 UTC. , java.time Using the example from the explanation: Instant epoch = OffsetDateTime.of(1900, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
BigInteger timeStamp = new BigInteger("C50204ECEC42EE92", 16);
// To get the whole part and the fraction right, divide by 2^32
double secondsSince1900 = timeStamp.doubleValue() / 0x1_0000_0000L;
// Convert seconds to nanos by multiplying by 1 000 000 000
Instant converted = epoch.plusNanos(Math.round(secondsSince1900 * 1_000_000_000L));
System.out.println(converted);
BigDecimal timeStamp = new BigDecimal(new BigInteger("C50204ECEC42EE92", 16));
// To get the whole part and the fraction right, divide by 2^32
BigDecimal bit32 = new BigDecimal(0x1_0000_0000L);
BigDecimal secondsSince1900 = timeStamp.divide(bit32);
// Convert seconds to nanos by multiplying by 1 000 000 000; round to long
long nanosSince1900 = secondsSince1900.multiply(new BigDecimal(TimeUnit.SECONDS.toNanos(1)))
.setScale(0, RoundingMode.HALF_UP)
.longValueExact();
Instant converted = epoch.plusNanos(nanosSince1900);
|
Convert Epoch seconds to date and time format in Java
Tag : java , By : pjkinney
Date : March 29 2020, 07:55 AM
|
Code to convert seconds to Date and time combination in java
Date : March 29 2020, 07:55 AM
|
Convert LocalTime for given zone to unix epoch seconds without the date component in java
Tag : java , By : user158193
Date : March 29 2020, 07:55 AM
|