Comma's in numbers.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Opcode
Enthusiast
Enthusiast
Posts: 138
Joined: Thu Jul 18, 2013 4:58 am

Comma's in numbers.

Post by Opcode »

Pretty self explanatory here. I am sure it wouldn't take much for the compiler to just ignore them. It's just too easy to get larger numbers like exampled below mixed up.

Code: Select all

100000000 -> 100,000,000
Of course you'd probably have to remove it from the line continuation feature.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Comma's in numbers.

Post by STARGÅTE »

:shock:

The comma is the separator for parameters in procedures!
What does the compiler in your idea here:

Code: Select all

Procedure Test(a, b=0)
	Debug a
	Debug b
EndProcedure

Test(123,456)
is 123,456 a whole number? Or Parameter for a and b?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Comma's in numbers.

Post by PB »

No programming language in the history of the world has ever had commas for numbers,
probably because commas aren't used to separate numbers in all languages worldwide.
Some use periods, some just dots, some use apostrophes, and some just use spaces.
And China separates every 4 digits, not every 3. Here's some information about it:

http://www.statisticalconsultants.co.nz ... /WF31.html

If you want something easier on your eyes for large numbers, why not help yourself?

Code: Select all

Procedure EZ(num$)
  ProcedureReturn ValD(RemoveString(num$,","))
EndProcedure

; Add 100000000 and 222222222 together:
Debug EZ("100,000,000")+EZ("222,222,222")
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Comma's in numbers.

Post by Tenaja »

PB wrote:

Code: Select all

Procedure EZ(num$)
  ProcedureReturn ValD(RemoveString(num$,","))
EndProcedure

; Add 100000000 and 222222222 together:
Debug EZ("100,000,000")+EZ("222,222,222")
Wow, talk about code bloat! Might work for an "occasional" number, but I certainly would not use that for numerous numbers.

Anyway, I have a compiler (not for PCs) that allows the underscore anywhere in the middle of a number. Comes in handy for binary, that's for sure. Syntactically, it works because the only other time an underscore can be next to a digit is if both are part of the same identifier name.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Comma's in numbers.

Post by luis »

Tenaja wrote: Anyway, I have a compiler (not for PCs) that allows the underscore anywhere in the middle of a number.
HLA (high level assembly) does that.
The ability to space out big decimal numbers, or the byte/words components in binary and hex numbers is really helpful.
If I ever had to write a language I would put this feature in it for sure :)
"Have you tried turning it off and on again ?"
A little PureBasic review
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Comma's in numbers.

Post by PB »

> Wow, talk about code bloat!

Actually, that sort of "bloated" code is needed any time that you
need to convert "normal" numbers to plain. Say you have a finance
app that needs to convert a table of numbers like "$1,234,567.00"
to just 1234567... how are you going to do it without a procedure?
Last edited by PB on Sun Sep 08, 2013 2:51 pm, edited 1 time in total.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Comma's in numbers.

Post by Little John »

luis wrote:
Tenaja wrote: Anyway, I have a compiler (not for PCs) that allows the underscore anywhere in the middle of a number.
HLA (high level assembly) does that.
Euphoria 4.x ( which is a Basic-like programming language, not a drug :-) ) allows it as well.
luis wrote:The ability to space out big decimal numbers, or the byte/words components in binary and hex numbers is really helpful.
Agreed.
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: Comma's in numbers.

Post by Korolev Michael »

May be there is a way to do something like popping tool tip? Like this:

Image
Former user of pirated PB.
Now registered user :].
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Comma's in numbers.

Post by PB »

That's a nice idea, Michael; but which character are you going to use?
As I showed above, commas aren't used in every language of the world.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Comma's in numbers.

Post by Danilo »

PB wrote:That's a nice idea, Michael; but which character are you going to use?
As I showed above, commas aren't used in every language of the world.
Underscore '_' is a good idea. Because numbers can't contain it. If a number is started (at parsing), ignoring any underscores would be possible.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Comma's in numbers.

Post by PB »

I'd prefer no numbers be touched, anyway. Are we coders or not?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Comma's in numbers.

Post by Danilo »

PB wrote:I'd prefer no numbers be touched, anyway. Are we coders or not?
So you meant locale system setting for a tooltip? 1,000,000 or 1.000.000?

Thought you meant code like: x = 1_000_000
because it should be possible from a point of a language parser.

Thing is, PB is fixed to english notation. It already uses points '.' for floats,
whereas a german parser would use comma ',' for floats. International users
are used to the english notation, so no problem (If, While, Repeat, Until, ...everything English anyway).
PB uses english syntax, and ignoring underscore in numbers should be possible.
So 1_000_000 becomes 1000000, and 1_0_0_0 becomes 1000.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Comma's in numbers.

Post by freak »

Just use a macro:

Code: Select all

Macro Num(a=,b=,c=,d=,e=,f=)
  a#b#c#d#e#f
EndMacro


Debug Num(1,000)
Debug Num(1,000,000)
quidquid Latine dictum sit altum videtur
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Comma's in numbers.

Post by Danilo »

freak wrote:Just use a macro:

Code: Select all

Macro Num(a=,b=,c=,d=,e=,f=)
  a#b#c#d#e#f
EndMacro


Debug Num(1,000)
Debug Num(1,000,000)
Nice idea, if you want to use comma ',' as thousands separator (english notation).
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Comma's in numbers.

Post by blueznl »

Well, we're supposed to use the 100.000.000,00 notation here in NL, and I hate it!

But to be honest, I would have no problem with the 100_000_000.00 variant. Not that I need it though, it just wouldn't bother me 8)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply