לפני 8 חודשים

@מתנסה-php-api

נראה לי שהקוד הבא יקצר לך את אחרי הנקודה לשני ספרות.

// קבלת נתונים מהמשתמש
$principal = $_GET['principal'];
 // סכום ראשוני
$monthlyPayment = $_GET['monthlyPayment']; 
// סכום לכל חודש
$annualInterestRate = $_GET['annualInterestRate']; 
// אחוז תשואה לשנה
$years = $_GET['years'];
 // כמה שנים
if($principal==null){print"read=t-הקישוא את הסכום הראשוני=principal,";
}elseif($monthlyPayment==null){print"read=t-הקש כמה נוסף בחודש=monthlyPayment,";
}elseif($annualInterestRate==null){print"read=t-הקש כמה אחוזים תשואה בשנה=annualInterestRate,";
}elseif($years==null){print"read=t-הקש את מספר השנים להשקעה=years,";}
 
 
else{
 
 
// חישוב ריבית חודשית
$monthlyInterestRate = $annualInterestRate / 12 / 100;
 
// חישוב מספר חודשים
$numberOfMonths = $years * 12;
 
// חישוב סך ההכנסה
$totalInvestment = $principal + ($monthlyPayment * $numberOfMonths);
 
// חישוב סך הריבית
 
$totalInterest = 0;
$balance = $principal;
for ($i = 1; $i <= $numberOfMonths; $i++) {
  $interest = $balance * $monthlyInterestRate;
  $totalInterest += $interest;
  $balance += $monthlyPayment + $interest;
}
 
// הדפסת התוצאות
 
 
$totalos=$totalInvestment + $totalInterest;
///    $totalos = str_replace("." , ".t-נקודה.d-" , $totalos);
///    $totalInterest = str_replace("." , ".t-נקודה.d-" , $totalInterest);
    
 $uy=(int)substr($totalos, 0, strpos($totalos, "."));
 $uy1=(int)substr($totalInterest , 0, strpos($totalInterest , "."));

 $string=(int)substr($totalos, ".", strpos($totalos, 2));
 $string1=(int)substr($totalInterest , ".", strpos($totalInterest , 2));

print "id_list_message=t-להלן התוצאות,הסכום הראשוני הוא  .n-$principal";
print".t- תשלום חודשי .n-$monthlyPayment";
print".t- על ידי  .n-$annualInterestRate.t- אחוזים למשך .n-$years.t- שנים שהם .n-$numberOfMonths.t- חודשים, סך הכל הכנסה ";
print".n-$totalInvestment";
print".t-סך הכל רווח ";
print".n-$uy1.t-נקודה.n-$string1";
print".t- סך הכל למשיכה "; 
print".n-$uy.t-נקודה.n-$string";
//עבור הדפדפן
print "<h2>תוצאות</h2>";
print "<h3>סכום ראשוני:</h3>" . $principal . "<br>";
print "<h3>תשלום חודשי:</h3>" . $monthlyPayment . "<br>";
print "<h3>אחוז תשואה שנתית:</h3>" . $annualInterestRate . "%<br>";
print "<h3>משך ההשקעה:</h3>" . $years . " שנים (" . $numberOfMonths . " חודשים)<br>";
print "<h3>סך ההכנסה:</h3>" . number_format($totalInvestment, 2, ".", ",") . "<br>";
print "<h3>רווח:</h3>" . number_format($totalInterest, 2, ".", ",") . "<br>";
print "<h3>סך הכל:</h3>" . number_format($totalInvestment + $totalInterest, 2, ".", ",") . "<br>";
 
 
 
 
}