add DecimalFormat function

This commit is contained in:
Jonathan Shook 2020-03-13 12:20:11 -05:00
parent 0826f2acb8
commit 81195a7848

View File

@ -0,0 +1,24 @@
package io.nosqlbench.virtdata.library.basics.shared.formatting;
import io.nosqlbench.virtdata.annotations.Example;
import io.nosqlbench.virtdata.annotations.ThreadSafeMapper;
import java.util.function.DoubleFunction;
/**
* Formats a floating point value to a string using the java.text.DecimalFormat
*/
@ThreadSafeMapper
public class DecimalFormat implements DoubleFunction<String> {
private final java.text.DecimalFormat format;
@Example({"DecimalFormat('.##')","converts a double value to a string with only two digits after the decimal"})
public DecimalFormat(String format) {
this.format = new java.text.DecimalFormat(format);
}
@Override
public String apply(double value) {
return this.format.format(value);
}
}