0

Split number

Hello i'm trying to split a number with a coma separated like 1850 to 18,50 or 12333 to 123,33, it could be 4 or 5 or 6 numbers and split with two number at the end?

Any help would be appreciated.

Thanks

Thierry

3 replies

null
    • Sean
    • 4 yrs ago
    • Reported - view

    I assume the comma is a decimal separator? This is one way to do it for a single record...

     

    let myNum := text(WholeNumber);
    let myNumLen := length(myNum);
    let myNum := substr(myNum, 0, myNumLen - 2) + "." + substr(myNum, myNumLen - 2, myNumLen);
    DecimalNumber := number(myNum)

     

    WholeNumber and DecimalNumber are Number fields. You can avoid using a second field by using this...

     

    let myNum := text(format(WholeNumber, "0"));
    let myNumLen := length(myNum);
    let myNum := substr(myNum, 0, myNumLen - 2) + "." + substr(myNum, myNumLen - 2, myNumLen);
    WholeNumber := number(myNum)

     

    Be sure to replace "." with "," and enter the code in a Button. Also, make sure the Number field format is set for 2 decimal places. That code updates the record that is currently selected. If you want to update all records use this...

     

    for r in select YourTable do
    let myNum := text(r.WholeNumber);
    let myNumLen := length(myNum);
    let myNum := substr(myNum, 0, myNumLen - 2) + "." + substr(myNum, myNumLen - 2, myNumLen);
    r.(DecimalNumber := number(myNum))
    end

    • Thierry_Grosjean
    • 4 yrs ago
    • Reported - view

    Sean,

    Thank you for your answer, I wil try it, but into the documententaion of Ninox I have found format(), like this:

    format('MyField', "#'###,##"), I put it to a formula" but it dont work.

    This code come on my items template, it's for the buying price, I dont want to have a customer he view this item cost 30CHF and buying price 20CHF, I prefer have Sell price 30CHF and buying price 00/002000 that is converted into a hidden formula field to 20,00CHF and the same for 00/00134000 would be 1'340,00CHF.

    Thierry

    • Sean
    • 4 yrs ago
    • Reported - view

    Thierry,

    I'm sorry, I misunderstood your original post. My solution was for converting whole numbers to decimal numbers so please disregard it.

    The number format is based on operating system settings for the Mac app and browser settings for the Ninox Cloud. I created a test database in my Mac app and changed my system settings so that ' was used for the thousands separator and , was used for the decimal separator and it worked correctly. When I selected "Number format" in the Mac app, it still showed "#,##0.00" as the format selection, but the numbers displayed as 1'234,56

    Sean

Content aside

  • 4 yrs agoLast active
  • 3Replies
  • 1417Views