Results 1 to 3 of 3

Thread: Separating thousands with comma

  1. #1

    Separating thousands with comma

    Is there an easier way to separate thousands with comma?

    Uses "Console"
    PrintL format$(123456789.123,"###,###,###.###")
    WaitKey
    
    In the code above, we would have to know beforehand how large the value to be printed is, and the code would fail to place all the commas if the value were larger.

    We could use

    PrintL format$(123456789.123,"###,###,###,###,###,###,###,###.###")
    
    to anticipate larger values, but I wonder if there is a more elegant solution.
    Last edited by paravantis; 29-08-2024 at 18:29.

  2. #2
    I am answering my own question.

    The code below does the job:

    Uses "Console"
    PrintL format$(123456789123456.123,"#,###.###")
    WaitKey
    

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,146
    Rep Power
    735
    Thank you for sharing the solution with others!

    I suspect even this could work:

    uses "console"
    
    printl format$(1212313212313.123456, "#,.000")
    
    waitkey
    
    We should expand the docs to reduce the guesswork.


    Petr
    Last edited by Petr Schreiber; 01-09-2024 at 17:54.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. Forum bombed by thousands of connections
    By ErosOlmi in forum Web and Forum
    Replies: 4
    Last Post: 16-01-2023, 09:12
  2. File Reading and separating "fields"
    By TheOne in forum File
    Replies: 5
    Last Post: 11-03-2011, 18:51

Members who have read this thread: 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •