SC Format: number fraction handling?
Forum rules
You might want to read this if you're looking for priority service
Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).
Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.
How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
You might want to read this if you're looking for priority service
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
Re: SC Format: number fraction handling?
Oh great! This should really solve that other issue I had with one of the script I posted. Apparently people who were under the German locale but were using commas as separator and periods for decimal places end up causing the script to fail. I could not really find a way to make it independent.
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: SC Format: number fraction handling?
You can always consult the Registry to see the current user settings: e.g. >> http://www.xyplorer.com/xyfc/viewtopic. ... 514#p54514Enternal wrote:Oh great! This should really solve that other issue I had with one of the script I posted.
Apparently people who were under the German locale but were using commas as separator and periods for decimal places end up causing the script to fail.
I could not really find a way to make it independent.
and then decide how to continue with your script.
.
-
admin
- Site Admin
- Posts: 67283
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: SC Format: number fraction handling?
So, looks like this is finally fixed for good! Was an interesting ride.

FAQ | XY News RSS | XY X
-
PeterH
- Posts: 2830
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: SC Format: number fraction handling?
To come to an end I just tested 0010
Still one thing to say: persons debugging a script in a locale with decimal separator ',' might be surprised that a variable that was assignet $i=1.2, now contains 1,2
OK: I think this was the only solution that makes sense - so it's OK. But I think it should be mentioned in help [maybe with Scripting/Remarks(1)?]
Same for new format "1,2", of course
Still one thing to say: persons debugging a script in a locale with decimal separator ',' might be surprised that a variable that was assignet $i=1.2, now contains 1,2
OK: I think this was the only solution that makes sense - so it's OK. But I think it should be mentioned in help [maybe with Scripting/Remarks(1)?]
Same for new format "1,2", of course
-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
Re: SC Format: number fraction handling?
@Stephen
Oh! Never thought about that. I will see if I can use that method. Although I'm hoping I don't have to resort to that. Registry stuff are annoying.
Uhh I think I"m doing something wrong. I switched my computer formatting to German(Germany) but my locale is still English (United States). The statement:
Actually resulted in 175 rather than 17,5
Also does FormatBytes suffer the same problem? For example:
1 kb converts to 1024 raw is perfect. 1.0 kb however converts to 10240 raw. But 1,0 kb converts to 1024 raw perfectly fine. Also under German(Germany) formatting for Windows.
Edit: This is all with the latest beta (13.30.0010)
Very interesting results 
Edit2: So it's not as independent as you had hoped. If i manually change the German(Germany) formatting settings on Windows with "." as the decimal and "," as the separator, it works as usual. But default settings for that format, no.
Oh! Never thought about that. I will see if I can use that method. Although I'm hoping I don't have to resort to that. Registry stuff are annoying.
Uhh I think I"m doing something wrong. I switched my computer formatting to German(Germany) but my locale is still English (United States). The statement:
Code: Select all
echo format(17.5);Also does FormatBytes suffer the same problem? For example:
Code: Select all
$SizeTarget = Input("Total Target Size", "Units of B, KB, MB, GB, or TB", "", "s");
$SizeTarget = FormatBytes("$SizeTarget", Raw);Edit: This is all with the latest beta (13.30.0010)
Code: Select all
echo 17.5 * 2; //350
echo -17.5 * 2; //-350
echo 17.5 + 17.5; //350
echo format(17.5); //175
echo format(17.5, "00.00"); //175,00Edit2: So it's not as independent as you had hoped. If i manually change the German(Germany) formatting settings on Windows with "." as the decimal and "," as the separator, it works as usual. But default settings for that format, no.
-
admin
- Site Admin
- Posts: 67283
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: SC Format: number fraction handling?
System Locale ID: 1033
Thread Locale ID: 1031
Default ANSI Code Page: 1252
Active Code Page: 1252 (ANSI - Lateinisch I)
DBCS Code Page: No
These are my German number settings:
To see the attached files, you need to log into the forum.
FAQ | XY News RSS | XY X
-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
Re: SC Format: number fraction handling?
Well it's gone... That was very odd. I was able to repeat the issue multiple times and then after a quick program restart and it was still there. The only difference when it started working was I fully quit XYplorer and then start it back up... 
Well anyway, I think it is fixed now so yeah!

I'm still confused on the usage though. So I wanted to make sure that the script function works with all users and it's up to them whether they want to use the German style of decimal and commas or the English way of doing the decimal and commas. How should I deal with that? Or should I just tell them explicitly to use the "any" windows method of commas for separators and periods for decimals?
Well anyway, I think it is fixed now so yeah!
I'm still confused on the usage though. So I wanted to make sure that the script function works with all users and it's up to them whether they want to use the German style of decimal and commas or the English way of doing the decimal and commas. How should I deal with that? Or should I just tell them explicitly to use the "any" windows method of commas for separators and periods for decimals?
-
admin
- Site Admin
- Posts: 67283
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: SC Format: number fraction handling?
There is a point in your script where users have to state fractional numbers?
FAQ | XY News RSS | XY X
-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
Re: SC Format: number fraction handling?
Well the script I was talking about was http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=10654
So the user have to enter the desired size to be selected. highend was using my script actually entered "1.0 kb" which caused problems since he was on a German locale. Yet what if another person decides to enter "1,0 kb" instead? And I'm sure fraction will be used like "1.25 mb". Or I could just force everyone to enter the desired total size in kilobytes but that would be horrible.
So the user have to enter the desired size to be selected. highend was using my script actually entered "1.0 kb" which caused problems since he was on a German locale. Yet what if another person decides to enter "1,0 kb" instead? And I'm sure fraction will be used like "1.25 mb". Or I could just force everyone to enter the desired total size in kilobytes but that would be horrible.
-
admin
- Site Admin
- Posts: 67283
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: SC Format: number fraction handling?
I see, I will do something about it.
FAQ | XY News RSS | XY X
-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
Re: SC Format: number fraction handling?
Awesome Don! Thanks it works perfectly!

I think you should add some more examples for it in the Help manual so that people won't get confused (well it's already a bit confusing since quotes affects the behavior.
Help Manual Examples:
Something like that... haha. Also do you think that the manual should warn that people should not use any thousand separators? Those really do wreak havoc.
I think you should add some more examples for it in the Help manual so that people won't get confused (well it's already a bit confusing since quotes affects the behavior.
Help Manual Examples:
Code: Select all
1. Echo FormatBytes("1.0 KB", RAW); // 1024
2. Echo FormatBytes("1,0 KB", RAW); // 1024
3. Echo FormatBytes(1.0 KB, RAW); // 1024
4. Echo FormatBytes(1,0 KB, RAW); // 1! WRONG
Example 1 & 2 Are Perfect for Locale Independent Scripts. Use Quotations.-
PeterH
- Posts: 2830
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: SC Format: number fraction handling?
Sorry: if I'm right this can't be correctEnternal wrote:Awesome Don! Thanks it works perfectly!![]()
I think you should add some more examples for it in the Help manual so that people won't get confused (well it's already a bit confusing since quotes affects the behavior.
Help Manual Examples:Something like that... haha. Also do you think that the manual should warn that people should not use any thousand separators? Those really do wreak havoc.Code: Select all
1. Echo FormatBytes("1.0 KB", RAW); // 1024 2. Echo FormatBytes("1,0 KB", RAW); // 1024 3. Echo FormatBytes(1.0 KB, RAW); // 1024 4. Echo FormatBytes(1,0 KB, RAW); // 1! WRONG Example 1 & 2 Are Perfect for Locale Independent Scripts. Use Quotations.
- "1.0 KB" is a string, not simply a number, and *must* be quoted.
- as I understood the change FormatBytes just interprets "1.0 KB" and "1,0 KB" the same.
This change is *not* the same as that for numbers before. That was done by changing an unquoted number like 1.2 to the local format, i.e. for German to 1,2 - after that all variables handling this number see and work local format.
But "1.2 hp" or "1,2 MB" are no numbers - so it would nor help here!
What you could do is:
Code: Select all
$x = "1.0" . " KB";
FormatBytes($x, RAW);Now as before the number to FormatBytes should always be in locale format - Don just *allowed* it to also be in 1.0 format - with the problem that the 1000-divider can't be recognized...
(Hope here's no part I misinterpreted
-
Enternal
- Posts: 1175
- Joined: 10 Jan 2012 18:26
Re: SC Format: number fraction handling?
No PeterH. You are absolutely right. *slams head against wall 
I pretty much got the Format and FormatBytes all mixed up in my head when I was reading through the beta changelog haha.
What you said makes complete sense. I don't know what I was thinking when I wrote FormatBytes(1,0 KB, RAW) (although in my script I did have correctly quoted). It's obvious that if you don't quote it, XYplorer will think that the "0 KB" and "1" are other parameter which does not exist for this particular script function as it only has 2 parameters but I'm imputing 3 instead.
I pretty much got the Format and FormatBytes all mixed up in my head when I was reading through the beta changelog haha.
What you said makes complete sense. I don't know what I was thinking when I wrote FormatBytes(1,0 KB, RAW) (although in my script I did have correctly quoted). It's obvious that if you don't quote it, XYplorer will think that the "0 KB" and "1" are other parameter which does not exist for this particular script function as it only has 2 parameters but I'm imputing 3 instead.
XYplorer Beta Club