It's not an easy thing to do: when scaling a panel, text point size of controls scales too, so you may retrieve it and use in your calculations. GetTextDisplaySize gives you the text lenght provided you create a metafont with the appropriate font name and size:
GetCtrlAttribute (panel, PANEL_NUMERIC, ATTR_TEXT_POINT_SIZE, &size);
GetCtrlAttribute (panel, PANEL_NUMERIC, ATTR_TEXT_FONT, font);
CreateMetaFont ("dummy", font, size, 0, 0, 0, 0);
GetCtrlVal (panel, PANEL_NUMERIC, &val);
sprintf (msg, "%.2f", val);
GetTextDisplaySize (msg, "dummy", NULL, &Twidth);
Twidth is the text width in pixels.
This works well if the panel maintains original proportions between its width and height, otherwise the controls are stretched so that returned text lenght does not meet actual text size (you could have texts high and compressed or on the contrary spread over the screen but very reduced in height). In this case you must calculate panel proportion and compare with original proportions adapting text width to actual panel shape. The code in this case must be extended a little (origRatio is the original proportion of the panel dimensions when loaded and must be saved in a global variables);
GetCtrlAttribute (panel, PANEL_NUMERIC, ATTR_TEXT_POINT_SIZE, &size);
GetCtrlAttribute (panel, PANEL_NUMERIC, ATTR_TEXT_FONT, font);
CreateMetaFont ("dummy", font, size, 0, 0, 0, 0);
GetCtrlVal (panel, PANEL_NUMERIC, &val);
sprintf (msg, "%.2f", val);
GetTextDisplaySize (msg, "dummy", NULL, &Twidth);
GetPanelAttribute (panel, ATTR_WIDTH, &width);
GetPanelAttribute (panel, ATTR_HEIGHT, &height);
ratio = (double)width / (double)height;
Twidth *= ratio / origRatio;
I don't know if the continuous creation of metafonts causes memory overload or memory leaks due to resources not released, but since there isn't a DestroyMetafont function it can be assumed that there is no problem acting this way, but this should be investigated a little.