Bug? Numberformat error

janderkan

Well-Known Member
Licensed User
Longtime User
Hi
This code
B4X:
    Dim I As Int=-1
    Log(NumberFormat(I,2,2))
    I=-100
    Log(NumberFormat(I,2,2))
    
    Dim D As Double=-1.5
    Log(NumberFormat(D,2,2))
    D=-100.5
    Log(NumberFormat(D,2,2))
gives this output
B4X:
0-1.00
0-100.00
0-1.50
0-100.50

I would like if the minus was the first character.

PS.
The IDE helps to write smart strings, but then it states that it is not supported.
Does anyone known if it will be supported in the future?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Confirmed and fixed for the next update. The fix is in B4RCore.cpp:
B4X:
B4RString* Common::NumberFormat(Double Number, byte MinimumIntegers, byte MaximumFractions) {
        PrintToMemory pm;
        B4RString* s = B4RString::PrintableToString(NULL);
        Long lng = 1;
        byte i;
        if (Number < 0) {
            pm.print("-");
            Number = -Number;
        }
        for (i = 0;i < MinimumIntegers - 1;i++) {
            lng *= 10;
            if (lng > Number) {
                MinimumIntegers = MinimumIntegers - i;
                while (MinimumIntegers > 1) {
                    pm.print(0);
                    MinimumIntegers--;
                }
            }
        }
        pm.print(Number, (Int)MaximumFractions);
        StackMemory::buffer[StackMemory::cp++] = 0;
        return s;
        
    }
 
Top