I am facing issue when saving the float values in DB.
I am creating a Textbox using HTML code, user has to key in any numeric value(decimal or without decimal) in it, and on click of save button, this value has to save in DB. When I enter any value without decimal, it works fine, but when I enter decimal value in textbox Ex: 10.1, it goes and save as 10.1000003814697
When I debug my code the parameter("txtValue") is going as 10.1 only, but when I check in DB the value saves as 10.1000003814697
In DB table the column DataType is float.
Requirement: -------------
I want to get the numeric values with 2 decimals places from computed variable without rounding off. i.e. 123456.646
then result should be 123456.64 instead of 123456.65
C# Code: ---------
Module Class to save Data in DB: ---------------------------------
[DataObjectMethod(DataObjectMethodType.Update)]
public void SavePIRTextboxValue(string PIRLabel, float textboxPIRValue, string ProjProcessSeqId, string ProjectId, string ProcessCode)
{
Modules.Project obj = new Modules.Project();
obj.InsertEPValue(PIRLabel, textboxPIRValue, ProjProcessSeqId, ProjectId, ProcessCode); //-- getting textboxPIRValue = 10.1 -- here is the parameter
}
public void InsertEPValue(string PIRLabel, float textboxPIRValue, string ProjProcessSeqId, string ProjectId, string ProcessCode)
{
int res = pvSaveData(PIRLabel, textboxPIRValue, ProjProcessSeqId, ProjectId, ProcessCode); //-- getting textboxPIRValue = 10.1 -- here is the parameter
}
private int pvSaveData(string PIRLabel, float textboxPIRValue, string ProjProcessSeqId, string ProjectId, string ProcessCode)
{
int result = 0;
try
{
result = base.Context.ExecuteNonQuery(SqlMaps.Project.InsertUpdateTextboxValue()
, new SqlParameter("@gPIRLabel", PIRLabel)
, new SqlParameter("@gtextboxPIRValue", textboxPIRValue) //-- getting textboxPIRValue = 10.1 -- here is the parameter
, new SqlParameter("@gProjProcessSeqId", ProjProcessSeqId)
, new SqlParameter("@gProjectId", ProjectId)
, new SqlParameter("@gProcessCode", ProcessCode));
}
catch(Exception ex)
{
throw ex;
}
return result;
}
internal static string InsertUpdateTextboxValue()
{
return @"
DECLARE @RC int
DECLARE @lblValue VARCHAR(10)
DECLARE @textboxPIRValue float -- here is the parameter
DECLARE @ProjProcessSeqId uniqueidentifier
DECLARE @ProjectId uniqueidentifier
DECLARE @ProcessCode varchar(50)
SET @lblValue = @gPIRLabel
SET @textboxPIRValue = @gtextboxPIRValue
SET @ProjProcessSeqId = @gProjProcessSeqId
SET @ProjectId = @gProjectId
SET @ProcessCode = @gProcessCode
EXECUTE @RC = [dbo].[P_UpdatePIRTextboxValue]
@lblValue
,@textboxPIRValue
,@ProjProcessSeqId
,@ProjectId
,@ProcessCode
SELECT 'Return Value' = @RC
";
}
Kindly let me know what is wrong in my code.
Thanks in advance.