# All Questions

Tagged with
60 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
735views

### Simple alternatives to floating-point when performing arithmetic on short string-encoded rationals

I am creating unit tests for a function that rounds "rational" numbers stored as strings. The current rounding implementation casts the strings to a floating point type: #include <boost/...
• 23
831views

### Convert Exponential values into float number on the fly in python

I am trying to show decimal values instead of exponential values as it is required for end user. You can see the code below, currentValue1='1.56e-65' print("%f" % float(currentValue1)) print(float(...
• 119
1vote
67views

### How does Python convert floats to strings internally?

In part of Python's documentation, there is a part that says: Interestingly, there are many different decimal numbers that share the same nearest approximate binary fraction. For example, the numbers ...
• 189
1vote
47views

### could not convert string to float although what is inside the string ' ' appears to be a number

I have some web traffic data downloaded from Google Analytics(downloaded as csv file) and cleaned the data into the following nested dictionary. The country dictionary Then, I desired to do some ...
• 11
1vote
40views

### What's the easiest way to prevent a user from entering a letter when the program asks for a number?

Say I have a float variable called "varFloat" and I use cin to allow the user to input a number, how can I prevent the user from entering a letter? I have a calculator program that breaks if a letter ...
1vote
123views

### How to print glm vector with manually specified precion?

I know about glm::to_string but I cannot find away to set precision of the string conversion. A few issues come up because of this. If I want to serialize glm structures, I won't be able to store ...
• 3,881
1vote
405views

### Python v2 convert scientific notation from string to float - values are changing

I'm using Python 2.7.11 and I have a text file with x,y,z values that represent values from a raster (lon, lat, value). I'm trying to import this file into a numpy array so I can continue processing ...
• 11
1vote
2kviews

### ValueError: could not convert string to float: in tkinter

I could not convert the entry widget values into float for the calculation inside function. from tkinter import * def bac_calc(): #gender_condition gend=gender.get() if gend == "Male": ...
1vote
50views

### Opening directories whose names contain real numbers

Is it possible in Fortran to open several folders, read the file inside it (there is only one file in each folder and each has the same filename), and then write the data (array 2x40 data, but only ...
1vote
268views

### Convert "numeric" string into some number type in Python without lose information

I'm creating a composite string for memorize id and sub id like this: 1.1 1.2 1.3 in this way: main_id=1 #not related to sub_id sub_id= 1 #or more by increment item = str(main_id)+"."+str(...
• 1,417
1vote
15kviews

### How to combine np string array with float array python

I would like to combine an array full of floats with an array full of strings. Is there a way to do this? (I am also having trouble rounding my floats, insert is changing them to scientific notation; ...
• 375
52views

### Displaying a Double as String rounded to what is significant in the number

I would like to represent a double as a string, without any extra 0s or without any rounding losing any its significant digits. Ignoring minor errors due to the nature of floating point.. e.g. when it ...
• 7,492
61views

### Override python built-in float() behavior

Old title: Convert scientific notation string without 'e' to float in Python I use a program that has some ...odd formats allowed. One format for real numbers is scientific notation without the letter ...
39views

### AttributeError: Can only use .str accessor with string values! python pandas

I am trying to convert all the cells value (except date) to float point number, I can successfully convert first 3 column but getting an error on the last one: Here is my code: df['Market Cap_'+str(...
• 151
575views

### ValueError: could not convert string to float using Pandas

Here I would like to convert all column values to floating point numbers, I have tried the code below but getting error, I have tried and removed ',' (as you can see in comments) but still getting ...
• 151
93views

### ValueError: could not convert string to float: 'Son'

I am getting the error- ValueError: could not convert string to float: 'Son' My dataset My code - data = pd.read_csv('/content/drive/MyDrive/Survey Result - Sheet1 (1).csv') feature_cols = ['Gender',...
• 119
24views

### idx = int(float(img_id)) ValueError: could not convert string to float:

I am getting this error when I try to read my files from a given directory. My code is: box_dir = '/home/test/' img_id = img_metas[0]['filename'][34:40] idx = int(float(img_id)) ...
33views

### I am having trouble evaluating the height in c#, when i introduce a number smaller than 1.5 still says come in

using System; namespace Tarea_C_ { class Program { static void Main(string[] args) { Console.Write("Write your age: "); int age = Convert....
35views

### Validating strings in postman? Is there a way to make adopt this code to work in this test

How can I adopt this code to include, that when the string value is "5.10", run the test collection as normal? Currently it works but it will just fail the test and this looks bad on my ...
• 33
613views

### TypeError: sequence item 0: expected str instance, float found

My code- out = [] for _, row in df.iterrows(): name = " ".join(row[0:4]) entities = [] i = 0 for n in row.index[0:4]: entities.append([i, i + len(row[n]), n]) ...
• 119
494views

### ValueError: could not convert string to float: '86,5484466552734'

When changing to a float using final.iloc[:,4:10]=final.iloc[:,4:10].replace(',', '.').astype(float) I am getting the following error: [ValueError Traceback (most ...
136views

### passing float numbers and strings to bash script

Possibly duplicated, but I could find the right solution. I would like to pass the parameters to my bash script. The script looks like this: echo \$1 echo \$2 and I am running the code with the ...
• 21
68views

### calculate checksum over an struct which contains float and string

I need to calculate checksum over a struct which contains floats and a string. The struct looks as below. typedef struct eeprom_struct { float detector_comp_ch0; float detector_comp_ch1; ...
• 37
48views

### String to float conversion not working php

I've a string value of the type "x.yy" which I want to convert to double/float. I've tried floatval(), doubleval() and float and double type casting as well but it only gives me "X"...
• 115
26views

### Txt parsing to 2D array and converting float

#include<string.h> #define ROW 1000 #define COL 1000" int main(){ char* pend; FILE* fp = fopen("data.txt","r"); if(fp == NULL){ printf("File error"); return 0; } else{ float ...
• 11
84views

### Transforming Brazilian Currency to Float

I have been trying to convert this Brazilian currency line into a float value. import pandas as pd df = pd.read_csv (r'OfficialDataSet.csv', dtype={'Income': str}) df['Income'].apply(type)....
41views

### Serial read in Python escape symbols

Hello friends I need write some script to measure low power on Arduino analog pin and read it on my computer in Python. I write simple script what allow me to read serial data from USB no problem in ...
42views

### How to convert commas to dot in Python

I have a text file containing some data with 3 columns as below, how can I convert them to dots (float) in Python 3.5? Thank you in advance ! 2,723 331,288 2,981592 2,701 331,208 2,980872 10,...
57views

### How do i convert a str to a float?

Input: df.groupby('Age Group').size() Output: 18 thru 24 352 25 thru 34 358 35 thru 44 341 45 thru 54 336 55 and Older 269 Under 18 103 dtype: int64 ...
37views

### Need help converting string or int to float

So I have been stuck on this one for a while and could use some help. I have been trying to fix this code and I keep getting an error about invalid syntax. So here is the code I need help with need to ...
45views

### Consistent Type Error regarding converting a string to a float in Python

I am working on an assignment for an Introduction to Programming course and would like some direction as to what I am missing and why I continue getting the same TypeError. I am able to assign my ...
375views

### Clean way to convert string to floating point number with specific precision?

I'm trying to convert strings of numbers that come from the output of another program into floating point numbers with two forced decimal places (including trailing zeros). Right now I'm converting ...
202views

### python (numpy, float, or decimal) - set min amd max decimal places in string representation

In Python (either in regular float, numpy, or decimal), is there a way to set both a min and max decimal places when getting the string representation? Say I want min decimal places to be 2, and max ...
• 1,058
78views

### python converting strings to floats resulting in error

I'm trying to convert strings from a txt file with charset: us-ascii. to np.float64. The data are just decimal numbers (positive and negative). with open(path) as fp: data=fp.readlines() ...
• 139
352views

### Data type conversion in GNURadio

I'm reading a stream of float digits from an external program to my GNURadio flowchart through "Socket PDU" bloc. However, the latter delivers a stream of strings instead of floats. I tried writting ...
24views

### Convert a list of a list of strings with decimals into floats

I have a list of a list that goes like this: Main_List: [ ['1.2','3.5'],[ ['5.8','8.3'] ] I am trying to convert one of the sublists into floats, here is what i did: Main_List[1] = [float(i) for ...
81views

### Can't load text from Python numpy for list string

I cant load text using numpy.loadtxt for the list of string inside 'file.dat': ['3317121918', '69', '1345', '15'] ['3317122000', '72', '1337', '20'] ['3317122006', '75', '1330', '20'] ['3317122012'...
• 133
1kviews

### Arduino String to float

I'm trying to convert a string of HEX to a single float value. The string is 4 bytes long. It was defined as: String B = ""; It is a substring of a longer string: B = input.substring(6,14); This ...
1kviews

### MBED RTOS convert Float to String/Char array

I am trying to convert a float number to a string to send over a serial connection. I have used sprintf and has previously worked BUT I am now running mbed RTOS which hangs when the sprintf line is ...
• 880
871views

### getting a string from text view into a double in android

Can someone help me with this problem am experiencing. I am trying to get a number from a text view and storing it into a double for calculation. Can someone help me where i went wrong? @Override ...
• 23
288views

### C++ string to floating point precision?

I have a question regarding floating point precision. I know that you can set precision of floating point number using setprecision(p) where p is the precision you can choose. But I only know to use ...
53views

### percentage function failing for calculator

I require expert assistance with a calculator. It is js for angular, so no typescript, but it runs and gives me a calculator. However the percentage function only works for numbers under 100. If I do ...
• 815
325views

### How to extract a float number from string using loop [python]

I use this loop to extract integers, what changes should I make to this loop which will accept decimal numbers. Here inputn is a string: def numberseeker(): global i, inputn, number, num while i <...
• 45
989views

### converting datatype from float to unicode and suppress decimal

I need to import the entire dataframe as string. The way I do this is via: df = read_csv('filename') df = df.astype('unicode') The problem with this is that the columns detected as float objects are ...
902views

### Determining Profit Python

I am writing a program to determine a car salesman profit for a new or pre-owned vehicle. I need to express all three outputs in currency format with the \$ sign right up against the first digit and ...
267views

### Django annotate cannot access model's floatfield

I am trying annotate a queryset with the object's distance from a user's provided location. Here is what I have so far: lat1 = request.POST['lat'] lon1 = request.POST['lon'] locations = Location....
• 3,902
49views

### Writing to a row in a CSV with data already in the row apart from one column in that row and inserting data into that empty coloumn

Currently trying to add a single item of data to a row in a CSV but it keeps adding it underneath the correct fieldvalue. Do I need to use a float? Really unsure here. Any help would be appreciated. ...
70views

### Why does using LONG_MAX in this context work, but using FLT_MAX not work?

I have a function written in ANSI C using MS Visual Studio 2012 on Windows 8.1, and the function takes in a char array lexeme with space for 20 chars and checks for a valid single-precision floating ...
• 305
813views

### PHP: string with decimals strips decimals when converting to float

With the function floatval() I try to convert a string with decimals to a float, but it doesn´t give me the desired result. Here´s the code: \$price_calc = str_replace(',','.',\$price); \$...