All Questions
Tagged with floating-point string
60
questions with no upvoted or accepted answers
2votes
2answers
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/...
2votes
0answers
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(...
1vote
1answer
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 ...
1vote
1answer
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 ...
1vote
1answer
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
0answers
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 ...
1vote
0answers
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 ...
1vote
2answers
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
0answers
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
3answers
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(...
1vote
3answers
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; ...
0votes
0answers
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 ...
0votes
2answers
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 ...
0votes
0answers
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(...
0votes
0answers
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 ...
0votes
0answers
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',...
0votes
0answers
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))
...
0votes
0answers
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....
0votes
2answers
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 ...
0votes
1answer
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])
...
0votes
1answer
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 ...
0votes
0answers
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 ...
0votes
0answers
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;
...
0votes
0answers
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"...
0votes
0answers
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 ...
0votes
1answer
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)....
0votes
2answers
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 ...
0votes
0answers
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,...
0votes
0answers
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
...
0votes
1answer
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 ...
0votes
2answers
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 ...
0votes
0answers
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 ...
0votes
1answer
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 ...
0votes
0answers
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()
...
0votes
0answers
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 ...
0votes
1answer
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 ...
0votes
0answers
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'...
0votes
1answer
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 ...
0votes
2answers
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 ...
0votes
1answer
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
...
0votes
0answers
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 ...
0votes
0answers
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 ...
0votes
1answer
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 <...
0votes
0answers
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 ...
0votes
1answer
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 ...
0votes
2answers
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....
0votes
1answer
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.
...
0votes
1answer
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 ...
0votes
2answers
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);
$...
0votes
1answer
3kviews
Convert float to NSString using custom format? ("xx:yy")
I'm getting a JSON string back from a web service I'm using, one of the items is a float, which is formatted like this: "1.2".
But I actually want to make it show like a time number, so like ...