Subject Re: convert a number like 1174.88 to a character field
From Lee Grant <camilee@nospam.comcast.net>
Date Sat, 6 Dec 2025 01:53:00 -0500
Newsgroups dbase.getting-started
Attachment(s) edfurchenumtostrnorounddisplay.PNG

On 12/3/2025 8:09 PM, ed furche wrote:
> i get a character field that rounds off the cents   i want to see "1174.88" not "1175"
> my code -   store ltrim(rtrim(str(amt))) to stramt.

Ed,

Along the lines of what Ken, while recovering, was trying to say, I
think, is that how you type your variable and is what matters here.
Here's a little thing I did using your variable names and ran it through
the Command Window to test it.

namt = 1174.88
cstramt = ""
? str(namt, 7,2, cstramt)


In other words, if you're using real numbers you want to convert to
strings, this is how you need to do it.

Assign the numeric to the numeric variable, namt
initialize the final form, string, in the variable cstramt
run the str() function on the numeric variable, with the size of all
parts off the numeric display, this will mean the decimal separator,
hence the number 7 (1174.88 has 7 numeric characters and separator), the
resultant number will be shown with the number of decimal places that
you wish to show, in case your number has mutliple decimal following
numbers (i.e. 1174.884568 (scientific or engineering numbers in
particular) would be shortened down to only '2' decimals as part of the
str() function limit size for display purposes. Finally, the converted
numeric is saved to the cstramt variable and will be displayed the way
you wish it to be, as the following pic will show.

Lee