Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing zeros from number

Tags:

How can I remove zeros (not just leading zeros, but zeros in every position) from a column containing Integers(numbers)?

For example : 0349010330 should become 349133

like image 695
ArLi91 Avatar asked Feb 24 '16 21:02

ArLi91


People also ask

How do I remove zeros at the end of a number in Excel?

In case you want to remove the same numbers of zeros from the end, you can apply a formula to solve it. Select the adjacent cell to the number you used. Type this formula =LEFT(D1, LEN(D4)-2)*1, D4 is the cell you will remove trailing zeros from, 2 is the number of zeros you want to remove.

How do I remove zeros from a number in Python?

Use the lstrip() Function Along With List Comprehension to Remove Leading Zeros in a String in Python. The lstrip() can be utilized to remove the leading characters of the string if they exist. By default, a space is the leading character to remove in the string.


1 Answers

Here is the solution (MySQL) for Hackerrank challenge The Blunder

SELECT CEIL((AVG(salary)) - (AVG(REPLACE(salary, '0', '')))) AS avg_salary FROM employees;
  • REPLACE() : used to remove 0 from salary.
  • AVG() : used to calculate average salary.
  • CEIL() : used to get next rounded integer.
like image 103
Omkar Singh Avatar answered Sep 20 '22 01:09

Omkar Singh