I'd like to have some pretty output that combines several local macros that have been formatted and put into a single line

I've tried multiple different configurations, but here's basically what I'd like

loc number1 = 12.20645161
loc number2 = 52.81451247
di "something here"

Desired Output: "number 1 is 12.2065 and number 2 is 52.8145"

I can format a single local macro:

di %12.4f `number1'

And I can concatenate two unformatted macros:

di "number 1 is `number1' and number 2 is `number1'"

But can't seem to do both simultaneously. Is there a way to format the macro early or do some inline formatting or append formatted strings to each other?

You are much of the way there, but there are some misconceptions here too.

You can't format a local macro in the sense that you can assign a format to a local macro. What you are doing is telling display to use a format in showing the value of that macro, but the macro itself is unaffected and the format doesn't stick. In fact the macro and the format are never associated in any strict sense; it's entirely a matter of the display command putting your instructions together, what to show and precisely how to show it.

This is not fundamentally different from similar commands in many other languages.

One solution is

loc number1 12.20645161
loc number2  52.81451247
di "number 1 is " %5.4f `number1' "and number 2 is " %5.4f `number2' 

Note that omitting the = signs assigns the numbers as string equivalents; there is no conversion to binary and back to decimal that way. The difference would not bite in this example.

Further notes:

  1. Avoid round() here like the plague. The solution to formatting problems is a format, not a numeric operation. It will work much of the time, but it's not guaranteed. It won't guarantee exactly what you want always because almost all decimal numbers cannot be held exactly as binaries and that will bite sometimes.

  2. You can do this

     local nice1 : di %5.4f `number1' 
     local nice2 : di %5.4f `number2' 
     di "number 1 is `nice1' and number 2 is `nice2'" 
    

That doesn't assign a format either, but it is the string manipulation you seek.

The way to think of it is: Macros hold strings. When you want to manipulate strings as strings, use string operations only.