1

I have some PHP code that works perfect and it gets information through SOAP. I need to show my clients the prices of some products but instead of '€3,56' it gives '€3,560'. Is there a way that i can get rid of the last number? I can't change anything in the SOAP document so i can only fix it with PHP.

2 Answers2

2

You said Is there a way that i can get rid of the last number? so if you want to remove last one you can use mb_substr there is an example

<?php 


$a = "$3,560";
$b =mb_substr($a, 0, -1);
print_r($b);
?>
Omer Tekbiyik
  • 4,255
  • 1
  • 15
  • 27
0

You could slice off the '0' with a string method ( substr('string', 0, -1 ) or you could turn it to a number and use modular division ( num % 10 ).

For the first answer, the 0 is the starting index and the -1 is the length (counting backwards from the end because you wish to strip off the last character).

willwile4
  • 63
  • 9