Jump to content

numbers problem


alin19

Recommended Posts

my client must insert a number and a method

 

method A or B(15 and 25)

 

if he chose number x and method A he will get this:

 

x+15/100*x

x

x-15/100*x

 

i have made this

 

<?php

 

if($_SERVER['REQUEST_METHOD'] == 'POST')

 

{

$a = $_POST['unu'];

$b = $_POST['doi'];

$x= number_format($a, 4, '.', '');

 

if (isset ($b)){

if ($b=='A)

$procent=15;

if ($b=='a')

$procent=15;

}

 

 

if (isset ($b))

{

if ($b=='B')

$procent=25;

        if ($b=='b')

$procent=25;

        }

if (isset ($procent))

 

{

 

 

$xmax = number_format(($a+($a*$procent/100)), 4, '.', '');

$xmin = number_format(($a-($a*$procent/100)), 4, '.', '');

 

}

 

 

}

}

 

?>

 

 

....

 

but i have some steps,

 

if ( 0<x<1000)

 

x, min and max      is the form      abcd

     

  a,b,c,d are numbers

 

if (  1000 <=x<10000)

 

x, min and max  is the form    abc0

 

if (  10000 <=x<100000)

 

x, min and max is the form  ab00

 

 

the big problem is when

 

x is 900

 

the i get

 

1.035  max over 1000

0.9000    x and min under 1000

0.765

 

i can do this by inserting a lot of if's  but it will be had to debug after it,

 

i don't know if i explaind very well,

can you help me?

Link to comment
Share on other sites

This is confusing to read.

 

I haven't analyzed what you're trying to do and I don't get it either, but:

if (isset ($b)){
   if ($b=='A)
   $procent=15;
   if ($b=='a')
   $procent=15;
   }
   

   if   (isset ($b))
   {
   if ($b=='B')
   $procent=25;
        if ($b=='b')
   $procent=25;
        }

I don't see the point with the IF statements everywhere. $procent doesn't change if the letter is capital or not.

 

if (isset ($b)){
   if ($b=='A' || $b=='a') $procent=15;
   if ($b=='B' || $b=='b') $procent=25;
}

Link to comment
Share on other sites

<?php
if ($_POST['submit'] && !empty($_POST['unu']) && !empty($_POST['doi'])){
$a = $_POST['unu'];
$b = $_POST['doi'];

if (preg_match("/a/i",$b) $procent = .25;
if (preg_match("/b/i",$b) $procent = .15;

echo $procent * $a . "<br />" . $a . "<br />" . ($procent+1) * a;
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.