So I have a whole number such as 45125 and want to convert to 451.25, or 54200 to 542.00. I want to be able to convert using both python and sql. Is there a way of doing it? I already tried researching but couldn't find a solution.
            Asked
            
        
        
            Active
            
        
            Viewed 47 times
        
    0
            
            
         
    
    
        devteight
        
- 3
- 3
- 
                    3So you just want to divide all numbers by `100`? – MSH Apr 18 '22 at 22:13
2 Answers
0
            In python,
print(format(54200/100, ".2f"))
In SQL,
SELECT
  CAST(54200/100 AS DECIMAL(7,2)) AS x;
 
    
    
        ML_Enthu
        
- 314
- 1
- 3
- 12
0
            
            
        You can use format specifiers and f-strings in python and do
newVal = 54200/100
print(f"{newVal:.2f}")
which outputs
542.00
The 2 in the print statement is the number of decimal places it displays.
See here, which has excellent explanations.
 
    
    
        kenntnisse
        
- 429
- 2
- 12