O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting data

Since we had to encode the Date and BigDecimal types so that they are correctly saved in the database, now we have to do the decoding:

Date date = getDate(dateLong);BigDecimal price = getPrice(priceLong);

For this, we will create two methods. The first one will handle Date:

private Date getDate(long dateLong) {    return new Date(dateLong);}

It will simply convert the milliseconds that are in the Long type format into the java.util.Date type.

Next is the conversion of the price to BigDecimal:

private BigDecimal getPrice(long priceLong) {    return new BigDecimal(priceLong).scaleByPowerOfTen(-4);}

Again, it takes the Long type and converts it to BigDecimal. However, since we have scaled the value by 4 decimal points, now we ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required