I don't think you will exactly achieve the same as in the UI easily.
Firstly 12.35 <> 12345
If you review the default imperial units (no project template) you'll see the spec for distance and length both have units of ft however:
'Distance 1234[']'
'Length 1' - 5 11/32"
So we know that 1ft <> 1234ft so clearly there will be no single input value that suits
The square brackets indicate that the units are set to not have the unit symbol at the end
Likewise we have UnitType of Degrees and SlopeDegrees (both are degrees) so both will need to be 12.345 to match UI. You'll have to pick out units such as these to decide what value goes in to match the UI.
After running the below which is likely the nearest you'll get to replicating the values in the UI you still have to check if you should be using 1.2345 or 12.345 or 123.45 or 12345 etc. for a specific unit.
Private Function Obj_230729a(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData,
ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) As Result
Dim UIApp As UIApplication = commandData.Application
Dim UIDoc As UIDocument = commandData.Application.ActiveUIDocument
If UIDoc Is Nothing Then Return Result.Cancelled Else
Dim IntDoc As Document = UIDoc.Document
Dim Units As Units = IntDoc.GetUnits
Const n1234 As Double = 1234.56789
Dim Out As New Dictionary(Of String, List(Of String))
For Each Item As ForgeTypeId In SpecUtils.GetAllSpecs
If UnitUtils.IsMeasurableSpec(Item) = False Then
Continue For
End If
Dim D As ForgeTypeId = UnitUtils.GetDiscipline(Item)
Dim SpecName As String = LabelUtils.GetLabelForSpec(Item)
Dim DispName As String = LabelUtils.GetLabelForDiscipline(D)
Dim FO As FormatOptions = Units.GetFormatOptions(Item)
Dim Str As String
Dim V As Double = n1234
Dim Ut As ForgeTypeId = FO.GetUnitTypeId
If Ut = UnitTypeId.Degrees OrElse Ut = UnitTypeId.Percentage OrElse Ut = UnitTypeId.SlopeDegrees Then
V /= 100
End If
V = UnitUtils.ConvertToInternalUnits(V, FO.GetUnitTypeId)
Str = UnitFormatUtils.Format(Units, Item, V, False)
If Out.ContainsKey(DispName) = False Then
Out.Add(DispName, New List(Of String))
End If
Dim L As List(Of String) = Out(DispName)
L.Add($"{SpecName} {Str}")
Next
For Each item As KeyValuePair(Of String, List(Of String)) In Out
Debug.WriteLine(item.Key)
item.Value.Sort()
For i = 0 To item.Value.Count - 1
Debug.WriteLine(item.Value(i))
Next
Next
Return Result.Succeeded
End Function