Results 1 to 4 of 4

Thread: floating point currency

  1. #1

    floating point currency

    I'm a little confused about what the floating point currency should do when a variable is dimensioned as currency.

    I thought it would provide something like .50 but when I use it all my variable holds is .5 (shouldn't it have like .50 instead?)

    If not, then how do I make sure that there are always two digits after the decimal?

    I'd like to see the variable printed to the console screen as like .50 instead of .5.

    Thanks
    Sandy

  2. #2

    Re: floating point currency

    Hi Sandy, if you want to make sure that the zero at the end is printed you can use the USING$ Command.

    Try the following script.

    [code=thinbasic]

    uses "Console"

    dim a as currency = 1.50

    dim aString as string = "#.##"

    console_cls

    console_writeline("Currency Test")

    console_writeline using$(aString, a)

    console_waitkey[/code]
    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: floating point currency

    Hi,

    using$ is very good, as it allows multiple numbers to be formatted.

    In special cases when 1 number is enough, you can try out FORMAT$:
    [code=thinbasic]
    uses "Console"

    dim a as currency = 1.50

    console_writeline("Currency Test")

    console_writeline("FORMAT$: "+FORMAT$(a, "#.00"))

    console_waitkey
    [/code]

    Those zeros mean you want exactly 2 decimal places. In format$, unlike using$, the ## would work as "2 digits when possible, lower number of them also accepted".


    Petr
    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

  4. #4

    Re: floating point currency

    Thanks. I'll give both a try to see which works best in my script.

    Sandy

Similar Threads

  1. different types of floating point?
    By kryton9 in forum Math: all about
    Replies: 11
    Last Post: 04-02-2011, 06:04
  2. Replies: 3
    Last Post: 09-10-2007, 21:56

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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