string() doesn't convert a double to a string in the string manipulator node.
When I try use a Double.ToString in a Java Snippet it gives me a non-recurring decimal. When I use a groupby and concatenate it does the same. Is there anyway around this?
If you are getting long numbers of chracters after the decimal point, try using DecimalFormat or String.format to control the output in a Java Snippet.
@richards99: I tried Number to String and the problem still prevails: 0.622 -> 0.62192744… @andyg: Unfortunately when I try that it just returns the integer value. @s.roughley: I haven’t programmed in Java ever and am unfamiliar with the language. However I did try
“”“
public class StringFormatExample{
public static void main(String[] args) {
System.out.printf(“Floating point number with 3 decimal digits: %.3f\n”,$COLUMN_NAME$);
}
}
”""
and it throws errors in a Java Snippet(simple) node.
Your cell must contain a recurring decimal to start with, its probably that when the number is rendered on-screen, its automatically rounded off. Therefore;
Before using the Number to String node, use the Round Number node, and specify how decimal points or significant figures you wish your number to contain.
Top marks to Simon for my most-overlooked Round Number node. For reference, in the Java Snippet(Simple) you need to set your return type to String, and then enter code something like:
Double dbl = $DblColumnName$; //Select by double clicking your double column to get the format correct after the = sign
String r = String.format ("%.3f", dbl);
return r;
Steve
PS - The Java Snippet (Simple) node was where I first learnt to write Java!