Discussion forum about PANORAMIC language

Mac, Windows & Android application development with PANORAMIC language
 
HomeFAQSearchRegisterMemberlistUsergroupsLog in
Latest topics
» Hello world.
by Mon Jun 19, 2017 1:37 am

» Biomorphes de PICKOVER
by Sun Jun 18, 2017 2:33 am

» In less than 10 lines of code
by Fri Jun 16, 2017 5:03 am

» Effect Dopler
by Fri Jun 16, 2017 3:29 am

» SuperEllipse
by Wed Jun 14, 2017 4:01 am

» Plants
by Wed Jun 14, 2017 3:38 am

» Mira's attractor
by Wed Jun 14, 2017 3:30 am

» Triangle of Sierpinski
by Wed Jun 14, 2017 3:22 am

» Esthétique polaire
by Wed Jun 14, 2017 3:16 am

» Butterfly effect : Lorenz equations
by Wed Jun 14, 2017 3:08 am

» Collision detection
by Tue Jun 13, 2017 5:09 am

» The Bees Laline Paull Epub Books
by Mon Oct 10, 2016 8:58 pm

» PANORAMIC for Mac OSX 10 is available
by Tue Aug 09, 2016 6:08 pm

» ide
by Sat Jul 16, 2016 12:27 am

» Can I change the program icon/logo in my application ?
by Thu Jul 07, 2016 3:32 am

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Share | 
 

 rounded values

View previous topic View next topic Go down 
AuthorMessage
Joerg



Number of posts : 19
Registration date : 2009-07-11

PostSubject: rounded values   Mon Oct 27, 2014 3:36 pm

Hi,

is there any Panoramic function to round decimals?

Thank you!!
Joerg
Back to top Go down
View user profile
kawe



Number of posts : 18
Registration date : 2010-11-07

PostSubject: Re: rounded values   Tue Oct 28, 2014 7:00 pm

Again - obviously not. You may again use an external function or simulate it.

e.g.:

dim number, int_part, frac_part
while number <> 0
input "value:"; number
int_part = int(number)
frac_part=frac(number)
print "rounded value:"; int_part + int(0.5 + 100*frac_part) / 100
end_while
terminate

btw: the window does not close if I omit 'terminate'. Is this a bug or a feature (most dialects will 'terminate' once the code has finished unless you explicitly wait (sleep, loop, ...) in the last line.


Last edited by kawe on Wed Oct 29, 2014 1:56 pm; edited 1 time in total
Back to top Go down
View user profile
Joerg



Number of posts : 19
Registration date : 2009-07-11

PostSubject: Re: rounded values   Tue Oct 28, 2014 8:07 pm

Thanks kawe,

to jump into the while loop, I think you need to have an initial value <> 0. But that's not the point. Nice function, thanks Very Happy TERMINATE closes the window, when I run the program...

dim number, int_part, frac_part
number = 1
while number <> 0
input "value:"; number
int_part = int(number)
frac_part = frac(number)
print "rounded value:"; int_part + int(0.5 + 100*frac_part) / 100
end_while
terminate
Back to top Go down
View user profile
papydall

avatar

Number of posts : 39
Age : 67
Localisation : TUNISIA
Registration date : 2013-03-16

PostSubject: Re: rounded values   Fri Oct 31, 2014 7:37 am

Here is source of a DLL in FreeBASIC (by Jean_debord) which allows to format a value.

Code:

#include "vbcompat.bi"

extern "Windows-MS"

function print_format(byref x as double, byref format_str as zstring ptr, byref x_str as zstring ptr) as integer export
  
  *x_str = format(x, *format_str)
  
  return 0
end function

end extern

Save under format.bas
 Compile by:
Code:

-fbc format.bas dll

If you cannot compile the DLL, you can download it on my Webdav accessible  since my signature :
username : panoramic@papydall
Password : panoramic123


You find the DLL in the folder Mes DLL, file Format.dll

Here is an example of use of the DLL

Code:

dim Amount, format$, xstr$, result% ,i%

dll_on "C:\Users\acer\Desktop\format.dll" : ' Please Adapt the path of the DLL
for i% = 1 to 20
    Amount = 100000*rnd(1000)
'    Try these various formats
    format$ = "  *** 00000000.00000"
    '  format$ = "  *** 00 000 000.000"
    '  format$ = "00,000,000.00 $"
    '  format$ = " 00 000 000.00 Dollars"
    '  format$ = "00 000 000.00 E"
    '  format$ = "00 000 000.00 £"

    xstr$ = format$
    result% = dll_call3("print_format", adr(Amount), adr(format$), adr(xstr$))
    print "Amount = ";xstr$
next i%

dll_off



I hope  that will be useful for you!
Back to top Go down
View user profile
Jack
Admin
avatar

Number of posts : 98
Registration date : 2007-07-01

PostSubject: Re: rounded values   Fri Oct 31, 2014 3:44 pm

There is no round() in Panoramic because there is a simple method to round a real with decimal : to load an integer with a real value.

In this example, i% is defined as an integer and r as a real number :

Code:
dim i%, r

r=1.2
i%=r
print i%

r=1.9
i%=r
print i%

After execution, you get 1 and 2.
Back to top Go down
View user profile http://panoramic.top-forum.net
kawe



Number of posts : 18
Registration date : 2010-11-07

PostSubject: Re: rounded values   Fri Oct 31, 2014 5:38 pm

Jack wrote:
There is no round() in Panoramic because there is a simple method to round a real with decimal : to load an integer with a real value.

But this is unmodified only useful if you want to round to the next integer 'half-up'. There are others rounding szenarios in the real world, a German example e.g.: http://home.f1.htw-berlin.de/scheibl/Glossar/Runden.htm

And then: you may want to round to the next ten, hundred or tenth, hundreth, ...
Back to top Go down
View user profile
Klaus

avatar

Number of posts : 18
Age : 68
Localisation : France
Registration date : 2013-03-23

PostSubject: Re: rounded values   Sun Mar 22, 2015 9:37 pm

Actually, you have to do it with an arithmetic formula (easily enough...), possibly embedded in a SUB...END_SUB construction. An other possibility might be the creation of a DLL function - might be worth to have a look on that if it's really important.
Back to top Go down
View user profile http://klaus.panoramic.voila.net/
Sponsored content




PostSubject: Re: rounded values   

Back to top Go down
 
rounded values
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Rounded header
» Setting & getting variable values
» Is it possible to store values from a TestCase and use them in a different TestCase?
» How to chose dropdown values in Selenium IDE?
» How to enter values at run time using c# in selenium

Permissions in this forum:You cannot reply to topics in this forum
Discussion forum about PANORAMIC language :: Panoramic for Windows :: Help?-
Jump to: