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.
Asked
Active
Viewed 45 times
1
-
Do you want to always remove the last digit? Only when that digit is 0? Only when there are 3 digits after the comma? – Patrick Q Feb 15 '19 at 14:18
-
Try this: [PHP - How to remove all specific characters at the end of a string?](https://stackoverflow.com/questions/2053830/php-how-to-remove-all-specific-characters-at-the-end-of-a-string) – Parantap Parashar Feb 15 '19 at 14:18
-
Think I'd be starting by asking why the service you're using is giving you that if that's not the price. That or what you're telling us isn't the real picture. – Jonnix Feb 15 '19 at 14:19
-
@PatrickQ i always need to remove tha last digit. – Joyce Paesschezoone Feb 15 '19 at 14:27
-
@JoycePaesschezoone Then see Omer's answer – Patrick Q Feb 15 '19 at 14:29
2 Answers
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