Top  Previous  Next

Examples > Bill > Tokens


Amounts can have fractional digits as in the following examples:









For amounts, where the fractional digits are replace by a hyphen, a special token must be defined, because a hyphen cannot be converted into a number directly.


Name:        Amount_

Parameter:        double& xSum

Text:        (\d+),\s?-

Action:        xSum += stod(xState.str(1));



The token is defined as a sequence of digits followed by a comma and a hyphen. Optionally a space can precede the hyphen


The digits before the comma only determine the value of the token. Because of the parenthesis around  "\d+" they can be accessed by xState.str(1). The return value of this expression is passed to  "stod" immediately, which converts the string containing the digits into a double value. This is added to the sum in xSum.




Normally an amount contains fractional digits. These are recognized by the token Amount:


Name:        Amount

Parameter:        double& xSum

Text:        (\d+),(\d\d?)

Action:        xSum += stod(xState.str(1) + "." + xState.str(2));


The comma can be followed either by one ore by two digits. The function can't convert expressions containing a comma (used in Germany). So temporarily the text presentation of the number is converted into a text, which can be converted by stod.


This page belongs to the TextTransformer Documentation

Home  Content  German