Author Topic: Help formatting numbers without printing to screen  (Read 10449 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help formatting numbers without printing to screen
« Reply #30 on: December 19, 2018, 09:32:09 am »

Going in depth with separator symbol for thousand and for decimal I find a very various situation in the world...
so my function with a Mode can be expanded to choose national writing mode for numbers...

see here how many kind of ways to write the same number....
https://en.wikipedia.org/wiki/Decimal_separator

Quote
The following examples show the decimal separator and the thousands separator in various countries that use the Arabic numeral system.

Style   Countries
1,234,567.89   Canada (English-speaking; unofficial), China, Hong Kong, Ireland, Israel, Japan, Korea, Malaysia, México, New Zealand, Pakistan, Philippines, Singapore, Taiwan, Thailand, United Kingdom, United States.
1234567.89   SI style (English version), Australia, Canada (English-speaking), China, Sri Lanka, Switzerland (officially encouraged for currency numbers only[40]).
1234567,89   SI style (French version), Albania, Belgium (French), Bulgaria, Canada (French-speaking), Czech Republic, Estonia, Finland, France, Hungary, Italy, Kosovo, Latin Europe, Norway, Peru, Poland, Lithuania, Russia, Slovakia, Slovenia, South Africa, Sweden, Switzerland (officially encouraged, except currency numbers[40]), Ukraine.
1,234,567·89   Ireland, Malaysia, Malta, Philippines, Singapore, Taiwan, United Kingdom (older, typically hand written)[41]
1.234.567,89   Argentina, Austria, Belgium (Dutch), Bosnia and Herzegovina, Brazil, Chile, Costa Rica, Croatia,[42][43] Denmark, Germany, Greece, Indonesia, Italy, Netherlands, Portugal, Romania, Russia, Slovenia, Spain,[44]Turkey, Vietnam.
12,34,567.89   Bangladesh, India (see Indian Numbering System).
1'234'567.89   Switzerland (computing), Liechtenstein.
1'234'567,89   Switzerland (handwriting).
1.234.567'89   Spain (handwriting).
123,4567.89   China (based on powers of 10 000—see Chinese numerals).
or you can expand your function to get Universal goal of accurate annotation for numbers...

so you can candidate your function for QB64 library  (a package must respect local convention... IMHO)
Programming isn't difficult, only it's  consuming time and coffee

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Help formatting numbers without printing to screen
« Reply #31 on: December 19, 2018, 10:32:49 am »
one sec..
I have to move this rock off me so I can see....
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Help formatting numbers without printing to screen
« Reply #32 on: December 19, 2018, 07:14:14 pm »
I wrote one exactly like that description but it is currently being held hostage in the lost realm of our old forum. Bummer.
unfortunately the wayback machine only shows the thread title in Libraries Format$() - or "PRINT USING for variables"

Offline Fifi

  • Forum Regular
  • Posts: 181
    • View Profile
    • My small QB64 contribution
Re: Help formatting numbers without printing to screen
« Reply #33 on: December 19, 2018, 07:40:26 pm »
That is very interesting, If I understand...
Italian uses a ","(comma) for a decimal notation and a "."(dot) for thousands separator?
If so we could change the function to ask for a delimiter.
 
thanks for that info.

French do so too (optionnaly using dots to separate the different float parts by group of 3 or not, and always using a comma to separate the decimal part).

e.g. both 1234567.89 and 1.234.567,89 are valid french notations.

Not sure but I think most european countries do so too, but of course England (that is not really a European country especially since their Brexit).

Meanwhile, I still think interfacing the C/C++ printf(), fprintf(), sprintf() and all the other input/output functions of the stdio.h library would be the easiest and best solution.

I don't know how hard it would be to do it since QB64 translates .bas code in .cpp code.

So, why not using _PRINTF(), _SPRINTF(), _FPRINTF() etc. with all their relevant parameters that also take care of the right or left aligment as well as leading spaces?

Just my two cents.
« Last Edit: December 19, 2018, 07:44:20 pm by Fifi »
It's better to look like an idiot for a short time while asking something obvious to an expert than pretending to be smart all your life. (C) Me.

FellippeHeitor

  • Guest
Re: Help formatting numbers without printing to screen
« Reply #34 on: December 19, 2018, 07:54:15 pm »
I wrote one exactly like that description but it is currently being held hostage in the lost realm of our old forum. Bummer.
unfortunately the wayback machine only shows the thread title in Libraries Format$() - or "PRINT USING for variables"

That was exactly it.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Help formatting numbers without printing to screen
« Reply #35 on: December 21, 2018, 10:27:18 am »

So, why not using _PRINTF(), _SPRINTF(), _FPRINTF() etc. with all their relevant parameters that also take care of the right or left aligment as well as leading spaces?

Just my two cents.

simple answer - just trying to stay "native" :-)
and IMHO, I only use QB64 for basic / fun programing, I have my heavy hitter languages for the Clydesdale work :-)
« Last Edit: December 21, 2018, 11:54:24 am by xra7en »
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline Fifi

  • Forum Regular
  • Posts: 181
    • View Profile
    • My small QB64 contribution
Re: Help formatting numbers without printing to screen
« Reply #36 on: December 21, 2018, 06:13:48 pm »
Hi xra7en


So, why not using _PRINTF(), _SPRINTF(), _FPRINTF() etc. with all their relevant parameters that also take care of the right or left aligment as well as leading spaces?

Just my two cents.

simple answer - just trying to stay "native" :-)
and IMHO, I only use QB64 for basic / fun programing, I have my heavy hitter languages for the Clydesdale work :-)

Sure, you can both be "native" and use QB64 for fun.

I don't have a problem with that.

However, since:

a) QB64 isn't a 100 per 100 full compatible QB4.5 product "yet" (and obviously never will be);
b) Nicely extend the language with a lot of new functions,
c) Is able to include native C/C++ libraries,
d) and generate C++ code...

why not extend it with new native stdio.h C/C++ functions with dedicated names (e.g. _PRINTF(), _SPRINTF(), etc)?

You will not be obliged to use such extended functions that, however could solve problems to others trying different solutions.

The perfect exemple are the printf(), sprintf(), etc. functions that provides responses that the "basic" PRINT USING does not.

However, since QB64 can include native C/C++ libraries, I'm still expecting to undersand how to "include" the stdio.h standard input/output library with a code sample, a question that noboby never ever responded to for over 2 years.

So, is QB64 really capable to include such a so basic and standard C/C++ library?

If yes, PLEASE show me how to do so.

Just my two cents.

Cheers.
Fifi
« Last Edit: December 21, 2018, 08:14:20 pm by Fifi »
It's better to look like an idiot for a short time while asking something obvious to an expert than pretending to be smart all your life. (C) Me.