Page 1 of 1

Calculer à 3 chiffres après la virgule / Calculate to 3 dec.

Posted: Wed Feb 25, 2015 1:20 pm
by NY152
Bonjour,

J'aimerais calculer un nombre qui aurait impérativement 3 chiffres après la virgule ; Exemple : 0.035 ou 0.000)

Comment s'y prendre ?

J'aimerais aussi savoir comment savoir si une variable contient un nombre négatif ?

D'avance, merci
_______________________________________________________________________________________________

Hello,

I would like to calculate a number that would have absolutely three decimal places; Example: 0.035 or 0.000)

How?

I would also like to know how to know if a variable contains a negative number?

In advance, thank you

Re: Calculer à 3 chiffres après la virgule / Calculate to 3

Posted: Wed Feb 25, 2015 1:30 pm
by Dude
NY152 wrote:I would like to calculate a number that would have absolutely three decimal places; Example: 0.035 or 0.000)
I would also like to know how to know if a variable contains a negative number?

Code: Select all

a.f=-0.005
b.f=0.040
c.f=a+b
Debug StrF(c,3)

If a<0 : Debug "'a' is negative" : EndIf

Re: Calculer à 3 chiffres après la virgule / Calculate to 3

Posted: Wed Feb 25, 2015 2:01 pm
by NY152
Mais si on test a < 0.xxx ca ne fonctionne pas. J'aurais aimé pouvoir le faire.
________________________________________

But if you test with a < 0.xxx it does not work. I wish I could do it.

Re: Calculer à 3 chiffres après la virgule / Calculate to 3

Posted: Wed Feb 25, 2015 2:24 pm
by T4r4ntul4

Code: Select all

a.f=-0.005
If a<0.222
  Debug "'a' is negative"
EndIf
is not a problem

Re: Calculer à 3 chiffres après la virgule / Calculate to 3

Posted: Wed Feb 25, 2015 4:55 pm
by Dude
NY152 wrote:if you test with a < 0.xxx it does not work
Yes it does. For a number to be negative, it has to be < 0. Show me your code so I can see what you're doing wrong. ;)

Re: Calculer à 3 chiffres après la virgule / Calculate to 3

Posted: Wed Feb 25, 2015 5:26 pm
by netmaestro

Code: Select all

cowbell.d = -0.123456           ; You can't limit the decimal places for the actual stored number
Debug cowbell
Debug StrD(cowbell, 3)          ; But you can control how many decimal places to display
cowbell=ValD(StrD(cowbell, 3))  ; Or truncate some if you wish
Debug cowbell
If cowbell < 0                  ; Test for negative
  Debug "NEED MORE COWBELL!!"   ; Should want more cowbell
EndIf

Re: Calculer à 3 chiffres après la virgule / Calculate to 3

Posted: Wed Feb 25, 2015 5:29 pm
by wilbert
netmaestro wrote:You can't limit the decimal places for the actual stored number
You could use an integer type and multiply everything by 1000 and divide by 1000 when presenting a result.

Re: Calculer à 3 chiffres après la virgule / Calculate to 3

Posted: Wed Feb 25, 2015 5:32 pm
by netmaestro
You could use an integer type and multiply everything by 1000 and divide by 1000 when presenting a result.
Sorry I was unclear. You can't limit the number of places but there's a couple of ways you can remove unwanted ones.

Re: Calculer à 3 chiffres après la virgule / Calculate to 3

Posted: Wed Feb 25, 2015 5:46 pm
by NY152
My idea is to calculate a bitrate automatically.

Is incremented by 1 as bitrate value quality 'Bit / Pixel' is not reached. I aim 0.076.

My essay:

Code: Select all

EnableExplicit
Global sLargeur.f
Global sHauteur.f
Global sIPS.f


Global Largeur.s
Global Hauteur.s
Global IPS.s

Global BitPerPixel.f

Global Bitrate.f = 100

Global pause.s

OpenConsole("Bit/Pixel Calculator")
  Print("Largeur de la vidéo : ")
  Largeur = Input()
  Print("Hauteur de la vidéo : ")
  Hauteur = Input()
  Print("Image par seconde de la vidéo : ")
  IPS = Input()
  sLargeur=ValF(Largeur)
  shauteur=ValF(Hauteur)
  sIPS=ValF(IPS)
  BitPerPixel=(sLargeur*sHauteur*sIPS)/(Bitrate*1024)
  Repeat
    If BitPerPixel < 0.076
        Bitrate=Bitrate+1
        BitPerPixel=(sLargeur*sHauteur*sIPS)/(Bitrate*1024)
        PrintN("+Bitrate: " + BitRate + " Bit/Pixel: " + BitPerPixel); For Info
      ElseIf BitPerPixel > 0.076
        Bitrate=Bitrate-1
        BitPerPixel=(sLargeur*sHauteur*sIPS)/(Bitrate*1024)
        PrintN("+Bitrate: " + BitRate + " Bit/Pixel: " + BitPerPixel)
    EndIf
  Until BitPerPixel=0.076
  Print("Bitrate: " +BitRate + " Bit/Pixel: " + BitPerPixel)
  pause=Input()
CloseConsole()