473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to retrieve float values from data base

Hi all
For ex am having the table student with fields student name and marks...Where as name is of the type string and marks float value....and having the records
Studentname Marks
aaa 10.5
bbb 15.3
Now am writing the query
Expand|Select|Wrap|Line Numbers
  1. Select * from table where Marks=10.5;
But while executing this query am getting 0 results....What can i do...Is there any way to solve this problem....Other than '=' operator for all (>,<,like,In)am getting the result...Please suggest me
Dec 10 '07 #1
7 4792
amitpatel66
2,367 Expert 2GB
Hi all
For ex am having the table student with fields student name and marks...Where as name is of the type string and marks float value....and having the records
Studentname Marks
aaa 10.5
bbb 15.3
Now am writing the query Select * from table where Marks=10.5;
But while executing this query am getting 0 results....What can i do...Is there any way to solve this problem....Other than '=' operator for all (>,<,like,In)am getting the result...Please suggest me
try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * from table WHERE ROUND(marks) = ROUND(10.5);
  3.  
  4.  
Dec 11 '07 #2
try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * from table WHERE ROUND(marks) = ROUND(10.5);
  3.  
  4.  
i think this may not be correct ...Why because we are using the round function means we are making that Float value as integer...I don't want to compare two integers i want to compare float values...because in my application even 0.4 value makes a lot difference...please tell me the reason for this and what to do...
Dec 11 '07 #3
mwasif
802 Expert 512MB
Hi sijayreddy,

Welcome to TSDN!!!

Kindly use CODE tags when posting source code.

What is the data type of 'Marks'? I know you have told above, but I want to make sure. There is no problem with your query. Or you can try this
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table WHERE Marks>=10.5 AND Marks<=10.5;
Dec 11 '07 #4
Hi sijayreddy,

Welcome to TSDN!!!

Kindly use CODE tags when posting source code.

What is the data type of 'Marks'? I know you have told above, but I want to make sure. There is no problem with your query. Or you can try this
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table WHERE Marks>=10.5 AND Marks<=10.5;
Hi
Hear am giving all the details how i created the table and inserted the data and the query for retrieving the data
Expand|Select|Wrap|Line Numbers
  1.      create table ex(name char,mark float,total float);
  2.     insert into ex values ('a',10.5,55.5);
  3.     insert into ex values ('b',1156.66,5656.65);
  4.    select * from ex where mark=10.5;    
  5.    select * from ex where mark=1156.66 ;
for the first query i.e Select * from ex where mark=10.5... getting the correct result but for the second select query select * from ex where mark=1156.66 query browser is returning ZERO result....
Kindly tell me the reason what is the reason for this and how to resolve the problem
Dec 12 '07 #5
mwasif
802 Expert 512MB
Change data type to DOUBLE using the below query
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE `ex` CHANGE `mark` `mark` DOUBLE( 14, 2 ) NULL DEFAULT NULL
Now test your query
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM ex WHERE mark=1156.66 ;
FLOAT values are not stored as exact values inside computer architecture.
Dec 12 '07 #6
Change data type to DOUBLE using the below query
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE `ex` CHANGE `mark` `mark` DOUBLE( 14, 2 ) NULL DEFAULT NULL
Now test your query
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM ex WHERE mark=1156.66 ;
FLOAT values are not stored as exact values inside computer architecture.
Thank u mwasif...it is working now...
Dec 13 '07 #7
mwasif
802 Expert 512MB
You are welcome. Postback whenever you need help.
Dec 13 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Jonathan Fielder | last post by:
Hi, I have a 32 bit integer value and I wish to find the single precision floating point value that is closest to but less than or equal to the integer. I also have a similar case where I need...
54
by: Andy | last post by:
Hi, I don't know if this is the correct group to post this, but when I multiply a huge floating point value by a really small (non-zero) floating point value, I get 0 (zero) for the result. This...
14
by: ziller | last post by:
Why is it that FLT_DIG (from <float.h>) is 6 while DBL_DIB is 15? Doing the math, the mantissa for floats is 24 bits = 2^24-1 max value = 16,777,215.0f. Anything 8-digit odd # greater than that...
16
by: Gerald Lafreniere | last post by:
{ float F=123.456000; F*=1000; // Actually I used a for loop F*=10 three times. printf("%f\n", F); } This will produce something like 123456.00XXXX, where XXXX are garbage digits. Why...
3
by: Neils Christoffersen | last post by:
Hey all, I wrote on Friday asking for some help moving a common subclass field up to the base class (original post and followup included below). This entails storing whole numbers inside float...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
1
by: joesfer | last post by:
I'm trying to develop a graphical user interface for a renderer i've got written in an unmanaged C++ DLL with C#. During the rendering process, several images are sent to a delegate as float*...
1
by: Peter Knörrich | last post by:
Hello, I've found another inconsistency, and looking through the list archives I can find mentions of funky stuff like print float('inf') giving Infanity
9
by: Lie | last post by:
I've noticed some oddly inconsistent behavior with int and float: Python 2.5.1 (r251:54863, Mar 7 2008, 03:39:23) on linux2 -345 works, but Traceback (most recent call last): File...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.