|
Post by David2 on Apr 28, 2014 5:21:12 GMT -8
Hi there,
i want to print Float and Double values? the cmd_number only shows Int.
Any idea?
thanks
|
|
|
Post by jamesbowman on Apr 28, 2014 8:01:53 GMT -8
You can use sprintf() to convert it to a string then use GD.cmd_text(). The downside is that sprintf() is quite slow and large. Or you can do the conversion yourself. To get a fixed 3-digit precision here the function 'plotfloat' draws each number in three parts: - the integer part is drawn right-justified
- the decimal point
- then the 3-digit fractional part
static void plotfloat(int x, int y, float f) { int font = 30;
GD.cmd_number(x - 2, y, font, OPT_RIGHTX | OPT_SIGNED, int(f)); GD.cmd_text( x, y, font, 0, "."); GD.cmd_number(x + 8, y, font, 3, int(1000 * abs(f))); }
void loop() { GD.ClearColorRGB(0x103000); GD.Clear();
float f = 3.142;
plotfloat(100, 50, 1.000); plotfloat(100, 100, 3.142); plotfloat(100, 150, -8); plotfloat(100, 200, -8.333);
GD.swap(); }
|
|