开发者

Convert Numeric to Character

开发者 https://www.devze.com 2023-03-18 20:21 出处:网络
I\'m not very familiar with FoxPro and I\'m running into problems trying to modify a report. I have a numeric value that I want to convert to text so that I can get the first four characters, but I am

I'm not very familiar with FoxPro and I'm running into problems trying to modify a report. I have a numeric value that I want to convert to text so that I can get the first four characters, but I am only able to get the first two characters.

When I execute the following in the command window: ? LEFT(STR(20110547),4)

The following value is 开发者_JAVA百科displayed: 20

I expected it to return 2011. Am I doing something wrong or is there something that I am not accounting for?

Thanks, C.R.


There are a couple of ways to do this:

LEFT(ALLTRIM(STR(20110547)),4)

You must LTRIM or ALLTRIM the STR function as it adds leading spaces. From the documentation:

STR( ) pads the character string it returns with leading spaces if you specify a length larger than the number of digits to the left of the decimal point. STR( ) returns a string of asterisks, indicating numeric overflow, if you specify a length less than the number of digits to the left of the decimal point.

You could also use the TRANSFORM function:

LEFT(transform(20110547),4)


FoxPro also has LEFTC(). It's the "same as LEFT() but used for strings with double-byte characters". Perhaps STR() is returning double-byte characters.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号