I have a problem showing a numeric field with 3 decimals in a tableview form.
The forms is created with SolutionModel and data is from a dataSet. After getting that dataSet I loop trough it and set the value of one of the fields.
I´m posting some images where you will see the problem, how the field is created and the results that I see in the console.
[attachment=2]Img1.png[/attachment]
[attachment=0]Img3.png[/attachment]
[attachment=1]Img2.png[/attachment]
I´m sure that I´m missing something, but could you please give me a clue??
Juan,
How is the dataprovider coeficiente defined?
Did you create it from an sql query or did you add the column to the dataset yourself?
Rob
Sorry Rob. I had not seen your answer before.
Here is the code that generates the data:
As you will see I create the dataProvider coeficiente_grupo in the SQL.
function obtenerCoeficientesGrupoReparto() {
_coeficientesGrupos = 0;
_coeficientesReales = 0;
var grupoPresupuesto = forms.lstGruposPresupuestos_GSComunidades.idgrupo_presupuesto;
var SQL = 'SELECT propiedades.idpropiedad, propiedades.coeficiente, \
CAST(0 AS numeric(12,4)) AS coeficiente_grupo, propiedades.nombre \
FROM propiedades \
WHERE propiedades.idinquilino=? \
AND propiedades.idcomunidad=? \
AND propiedades.idtipo_propiedad IN \
(SELECT DISTINCT grupos_presupuestos_tipos_propiedades.idtipo_propiedad \
FROM grupos_presupuestos_tipos_propiedades \
WHERE grupos_presupuestos_tipos_propiedades.idgrupo_presupuesto=?)\
ORDER BY propiedades.nombre';
var aArgs = new Array();
aArgs.push(globals.currentInquilinoID);
aArgs.push(globals.currentSucursalID);
aArgs.push( (grupoPresupuesto == null ? 0 : grupoPresupuesto));
var _ds = databaseManager.getDataSetByQuery('gscomunidades', SQL, aArgs, -1);
var totalCoeficientes = 0;
if (_ds.getMaxRowIndex() > 0) {
// Calculamos el Total de Coeficientes del Grupo de Reparto
for (var i = 1; i <= _ds.getMaxRowIndex(); i++) {
totalCoeficientes = totalCoeficientes + _ds.getValue(i, 2);
}
// Calculamos los Coeficientes que le Pertenecen
for (var j = 1; j <= _ds.getMaxRowIndex(); j++) {
var coeficienteGrupo = globals.ROUND( (_ds.getValue(j, 2) * 100) / totalCoeficientes, 3);
_coeficientesGrupos = _coeficientesGrupos + coeficienteGrupo;
_ds.setValue(j, 3, (coeficienteGrupo));
//application.output(_ds.getValue(j, 3));
}
}
_coeficientesReales = totalCoeficientes;
return _ds.createDataSource('coeficientes');
}
jasantana:
Sorry Rob. I had not seen your answer before.
Here is the code that generates the data:
As you will see I create the dataProvider coeficiente_grupo in the SQL.
function obtenerCoeficientesGrupoReparto() {
_coeficientesGrupos = 0;
_coeficientesReales = 0;
var grupoPresupuesto = forms.lstGruposPresupuestos_GSComunidades.idgrupo_presupuesto;
var SQL = 'SELECT propiedades.idpropiedad, propiedades.coeficiente, \
CAST(0 AS numeric(12,4)) AS coeficiente_grupo, propiedades.nombre \
FROM propiedades \
WHERE propiedades.idinquilino=? \
AND propiedades.idcomunidad=? \
AND propiedades.idtipo_propiedad IN \
(SELECT DISTINCT grupos_presupuestos_tipos_propiedades.idtipo_propiedad \
FROM grupos_presupuestos_tipos_propiedades \
WHERE grupos_presupuestos_tipos_propiedades.idgrupo_presupuesto=?)\
ORDER BY propiedades.nombre';
var aArgs = new Array();
aArgs.push(globals.currentInquilinoID);
aArgs.push(globals.currentSucursalID);
aArgs.push( (grupoPresupuesto == null ? 0 : grupoPresupuesto));
var _ds = databaseManager.getDataSetByQuery('gscomunidades', SQL, aArgs, -1);
var totalCoeficientes = 0;
if (_ds.getMaxRowIndex() > 0) {
// Calculamos el Total de Coeficientes del Grupo de Reparto
for (var i = 1; i <= _ds.getMaxRowIndex(); i++) {
totalCoeficientes = totalCoeficientes + _ds.getValue(i, 2);
}
// Calculamos los Coeficientes que le Pertenecen
for (var j = 1; j <= _ds.getMaxRowIndex(); j++) {
var coeficienteGrupo = globals.ROUND( (_ds.getValue(j, 2) * 100) / totalCoeficientes, 3);
_coeficientesGrupos = _coeficientesGrupos + coeficienteGrupo;
_ds.setValue(j, 3, (coeficienteGrupo));
//application.output(_ds.getValue(j, 3));
}
}
_coeficientesReales = totalCoeficientes;
return _ds.createDataSource('coeficientes');
}
Hi:
Change
var coeficienteGrupo = globals.ROUND( (_ds.getValue(j, 2) * 100) / totalCoeficientes, 3)
by
var coeficienteGrupo = globals.ROUND( (_ds.getValue(j, 2) * 1000) / totalCoeficientes, 3)
Best regards
Solved.
As I could see in the console that values were well calculated the problem had to be in the data definition. I have changed the type casting in the SQL sentence to double precision and now it shows 3 decimals.
I got it working but I would really like to know why it did not work with the type casting numeric(12,4).