// Gets the feature type name
String typeName = myDataStore.getTypeNames()[0];

// Create the style
Style style = null;

// Creates rules
// In this example, I just have 1 rule
Rule[] rules = new Rule[1];

// Create the style builder and the filter factory
StyleBuilder sb = new StyleBuilder();
FilterFactory ff = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());

// Creates the font array
// Be careful: there is a Font class from org.geotools.styling
// and a Font class from java.awt
org.geotools.styling.Font[] fontArray = { sb.createFont(new Font("sansserif", Font.PLAIN, 12)) };

// Search for the filter function
Function format = null;

// The name of the function is the one returned by the getName method
// not the class name
try {
			format = ff.function("NumberFormat", ff.property("depth"), sb
					.literalExpression("#.##"));
} catch (Exception e) {
			logger.error(e);
}

// Creates the text symbolizer
// For this example, the fill is set to null as well as the halo, which
// is apparently very slow to render
TextSymbolizer text = sb.createTextSymbolizer(null, fontArray, null, format, sb
					.createPointPlacement(0.0, 0.0, 0.0), "");

// Adds the symbolizer to the rule
rules[0] = sb.createRule(text);

// Creates a feature style
FeatureTypeStyle fts = sb.createFeatureTypeStyle(typeName, rules);

// Creates the style
style = sb.createStyle();

// Adds the feature style to the style
// This method is deprecated, but in geotools 2.5, there is no
// other way to do it
style.addFeatureTypeStyle(fts);