# Format a decimal to string

I didnt develop this code. I want to modify the last line.
The promodsc will be a negative number with decimal value. I want to eliminate the sign and decimal. For example promodsc is -4.99. I want it change to 499. The rest of command will give me 0000000499+ string I need. What do I need to change here?

REPLACE TAX_AMT   WITH RIGHT("0000000000" + ALLTRIM(B->TAXTOTAL),10) + "+"
REPLACE FRT       WITH RIGHT("0000000000" + ALLTRIM(B->SHIPTOTAL),10) + "+"
REPLACE BPAY_TYP  WITH "04"
REPLACE DISC_AMT  WITH RIGHT("0000000000" + ALLTRIM(b->promodsc),10) + "+"
FoxPro

Last Comment
jrbbldr
jrbbldr

The VFP Function STR() will convert a Numeric to a String.

If you look in your VFP Help for that funcion you will see it described in detail.

Another VFP function which may work for you is the TRANSFORM() function.
Again look into your VFP Help for more explanation

Lastly if you want to Pad out the string value to a fixed number of digits you will likely want to use the PADL() or PADR() function (see your VFP Help)

Note that since you seem to want to change the numeric value (example:  from -4.99 to 499) I'd recommend doing that (maybe in a temporary cursor) PRIOR to converting the value to a String.

Perhaps something like:
nTestValue = -4.99
nNewTestValue = ((-1 * nTestValue) * 100)
cNewTestValue = ALLTRIM(STR(nNewTestValue))
If you have questions about any individual line, look up the function in your VFP Help.

Good Luck
SOLUTION
JF0

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
cebu1014

I use this command.

Resulting error message..
Function argument value,type or count is invalid.
Pavel Celba

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
jrbbldr

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
JF0

Probably the problem is that your data type is character and I assumed it was numeric. Try this:

jrbbldr: omitting the 2nd parameter is quite alright.
Pavel Celba

If  ALLTRIM(b->promodsc) was working as stated in the question then b->promodsc must be character.

jrbbldr

If indeed the value of   b.promodsc   was a character instead of a numeric (as suggested above by: example promodsc is -4.99)  then by breaking the complex code down to its most simple components in a step-by-step manner would show you specifically where the problem existed.

For example if you should try the following on a Character value, you will get an error message which is telling you that the value cannot be run within the ABS() function.
?ABS(b.promodsc)

Good Luck
jrbbldr

If the field type of    b.promodsc   is character, then you obviously do not need to do the Functions which relate to Numeric values.

Instead you can get rid of the minus sign (a character) merely by using STRTRAN() or CHRTRAN()
And you can also get rid of the decimal point (a character) by using STRTRAN() or CHRTRAN()

Good Luck
FoxPro

Visual FoxPro (VFP), and its predecessor FoxPro, is a data-centric, object-oriented, procedural, database programming language and IDE from Microsoft last released in 2007 that still has some active use due to its low cost of deployment and fairly rapid development. In 2008, Microsoft released a set of add-ons for VFP's xBase components to allow interoperability with various Microsoft technologies. It allows data processing against its native file-based data tables or database servers such as SQL Server.

11K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts

TRUSTED BY