PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 17, 2022

[FIXED] how to convert single quotes string to number in python

 October 17, 2022     int, python, single-quotes, string     No comments   

Issue

I have a number of type string with single quotes. e,g

var = '2,000'
type(var) # <class 'str'>

I want to convert it to int.

I have tried int(var) But it gives an error

invalid literal for int() with base 10: '2,000'


Solution

If your number contains ',' then you should use this.

 > var = '2,000'
 > int(a.replace(',', ''))
 > 2000

else this

 >  var = '2000'
 >  i = int(var)


Answered By - Sanjit Prasad
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing