Couple of items about VAL()

This forum is meant for questions about the Visual FoxPro Language support in X#.

User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

Couple of items about VAL()

Post by kevclark64 »

#1: I noticed that the default decimal setting for XSharp is 2, but the following code using VAL returns only one decimal place:

Code: Select all

local valreturn
valreturn=val("7.451")   // returns 7.5
Shouldn't that return 7.45 ?

#2: In Foxpro, if a dollar sign is prepended to an amount string then VAL() returns a currency variable

Code: Select all

local valreturn
valreturn=VAL("$7.45") // returns 7.4500 and VARTYPE=currency in Foxpro; returns 0 and vartype=long in XSharp
Foxpro does not support any other currency symbols beside the dollar, which seems rather US-centric. It might be good if XSharp supported other common currency symbols as well.
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Couple of items about VAL()

Post by robert »

Kevin,
Thanks for the report. We'll make sure that the $ sign will be recognized by the Val() code and will return a Currency from that.
Accepting other currency symbols is another thing. What we can do is this: always recognize the $ character and also the symbol from the settings in the NumberFormatInfo from the current thread (https://docs.microsoft.com/en-us/dotnet ... encysymbol)
I have created a ticket for this: https://github.com/X-Sharp/XSharpPublic/issues/385

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4905
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Couple of items about VAL()

Post by Chris »

Hi Kevin,

In addition to what Robert said, about #1, I could not reproduce this. Can you please post a complete example showing this?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FoxProMatt

Couple of items about VAL()

Post by FoxProMatt »

I could not reproduce error # 1 either...

See:
2020-05-06 05_38_02-VPF Xsharp test app 1 (Running) - Microsoft Visual Studio.png
2020-05-06 05_38_02-VPF Xsharp test app 1 (Running) - Microsoft Visual Studio.png (8.49 KiB) Viewed 731 times
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

Couple of items about VAL()

Post by kevclark64 »

When I said the value of valreturn was 7.5, I determined that by using the debugger and holding the cursor over the valreturn variable, rather than actually printing it. If you print it, it does come out as 7.451. I notice, however, that while the debugger gives the 7.5 value while holding the cursor over valreturn, if you dig down into the properties of valreturn it says the value is 7.451. I don't know whether that difference in reported value is a debugger error or just the way the debugger works.

I think, though, that the 7.451 value is still the wrong return value (or at least not what Foxpro would return) since DECIMALS is set to 2.
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

Couple of items about VAL()

Post by mainhatten »

Kevin Clark wrote:Shouldn't that return 7.45 ?
Nope. In Vfp check

Code: Select all

WAIT WINDOW STR(valreturn, 10, 5)
#2: In Foxpro, if a dollar sign is prepended to an amount string then VAL() returns a currency variable

Code: Select all

local valreturn
valreturn=VAL("$7.45") // returns 7.4500 and VARTYPE=currency in Foxpro; returns 0 and vartype=long in XSharp
Foxpro does not support any other currency symbols beside the dollar, which seems rather US-centric. It might be good if XSharp supported other common currency symbols as well.
Even weirder at first encounter in vfp:

Code: Select all

SET CURRENCY TO "§"
WAIT WINDOW VAL("$7.864")
Actually having only a single marker to decide if a string is a currency is probably a benefit, as comparing to user machine setting might introduce further problems.
User avatar
Chris
Posts: 4905
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Couple of items about VAL()

Post by Chris »

Hi Kevin,

Thanks for the clarification! I did a couple tests with VFP and this:

Code: Select all

LOCAL u
u = 123.456
? u
u = VAL("123.456")
? u
returns 123.456 and 123.46, so in VFP, even if decimals is set to 2, in the first case it actually prints 3 decimal points. So apparently the difference is only in how Val() works compared to X#/VO, if I understand it correctly, in VFP it uses the DECIMALS setting to decide how many digits to parse and discards the rest, is that correct? Will log this as a bug to be fixed.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

Couple of items about VAL()

Post by mainhatten »

Chris wrote:in VFP it uses the DECIMALS setting to decide how many digits to parse and discards the rest, is that correct? Will log this as a bug to be fixed.
Hi Chris,
not the way I see it:

Code: Select all

? SET("Decimals")
u = VAL("123.456")
? STR(u, 10,5)
User avatar
Chris
Posts: 4905
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Couple of items about VAL()

Post by Chris »

Thanks, I was wrong. So I tried this:

Code: Select all

CLEAR
SET DECIMALS TO 2
LOCAL uLiteral,uVal
uLiteral = 123.456
uVal = VAL("123.456")
? uLiteral, uVal
? STR(uLiteral , 10 , 5), STR(uVal , 10 , 5)
and the result is

123.456 123.46
123.45600 123.45600

do you know what causes the difference in the first case, between printing (without Str()) the value that is assigned as a literal in contrast to the same value that was assigned from Val() ?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

Couple of items about VAL()

Post by kevclark64 »

It seems like STR and VAL should both respect the default DECIMALS setting, but in Foxpro they don't. VAL respects the DECIMALS setting but STR does not. So that, with DECIMALS set to 2:

Code: Select all

? STR(7.451)  // prints 7 because the default decimals for STR is 0 regardless of the DECIMALS setting
? STR(7.451,5,3) // prints 7.451
? VAL("7.451") // prints 7.45
You can use SET DECIMALS and SET FIXED together so that floats are displayed as a set length; but STR still doesn't respect this:

Code: Select all

SET DECIMALS TO 1
SET FIXED OFF
u=7.451
? u   //prints 7.451
SET FIXED ON
? u   //prints 7.5
? str(u)  //prints 7
Post Reply