ValC()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Well, use integers throughout your software, but add a dot before DISPLAYING them to Joe User, so 33.33 would be stored as 33333.
This is what I do currently :D

I use two procedures (because I might have to add a VAT as well for a customer... so I split it up)

Code: Select all

Procedure TOTALTAX()
;******** set tax rate in pref file - so read it!
ts$ = GetGadgetText(#Text_SUBT)
  a.d = ValD(ts$)
    pronk.d = a * Taxrate.d ; already loaded and global variable
      pronk$ = StrD(pronk,2) ; clip it at 2nd place
        SetGadgetText(#Text_TAX, pronk$) ; *** set tax
          grand.d = a + pronk
            grand$ = StrD(grand,2)
              FRAGGIT$ = moneysign$+" " + grand$
SetGadgetText(#Text_PAYTHIS, FRAGGIT$)

EndProcedure

Procedure TOTALTICKET()
; *** RESET all variables each time this is called
Result = 0
Result$ = ""
Cost$ = ""
subtotal.d = 0
subtot.d = 0
; *** This is what holds the restaurant ticket
Result = CountGadgetItems(#ListIcon_TICKET)

For t = 0 To Result
  Result$ = GetGadgetItemText(#ListIcon_TICKET, t, 2) ; money in #2 column
    subtot.d = ValD(Result$) ; turn it into a number
      subtotal.d = subtotal + subtot ; add it to grand total
Next
      RESU$ = StrD(subtotal,2) ; round off at 2nd decimal place
       SetGadgetText(#Text_SUBT, RESU$) ; plunk it

TOTALTAX() ; figure the tax

EndProcedure
8)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

@ Trond and blueznl

Okay, I understand what you mean by accuracy.

I guess there are types of accuracy then. :)

Had I used some integer based data type with the finance company software then there would have been inaccuracies over time. (Which could have meant the companies using it might have been fined by the ATO for understating tax - and hammered by some clients for overstating interest).

It is interesting when you get into it, actually. A lot comes down to definitions. For example, with rounding, if you search on this you find many defs, including things like "stochastic rounding" which randomly rounds up and down on equidistant fractions (eg 0.5).
Dare2 cut down to size
Post Reply