FoxInCloud
Problem inserting number with decimals in list
Gravatar is a globally recognized avatar based on your email address. Problem inserting number with decimals in list
  Michele
  All
  Oct 25, 2021 @ 07:58am

WHen i enter a numeric value with decimals when i confirm data the decimal number became part of the integer... For example i isert 1234,1 and i find 12341 Here is the screenshot In the same situation i have the problem reading data- In this example in table i have 10010,20 but the decimal part has been lost

Here is my code

Local abSelect, abRecno, abPoint, abSep, cTxtID, cChkID, cHTML, cScript, nTabIndex

cHTML = ''
nTabIndex = 10
If Used("SaldiMag")

	abRecno  = abRecno('SaldiMag') && restores recno() automatically
	abSelect = abSelect('SaldiMag') && restores select() automatically
	abPoint = abSet('point', '')
	abSep = abSet('separator', '')
	cTxtID = wcID(this.columns(4).txt)
	
	Scan && always starts at BOF(); you can use SCAN FOR to filter
		TEXT to cHTML textmerge additive noshow flags 3
			<div class="col-sm-12 panel panel-default" data-rowid="<<Recno("SaldiMag")>>">
				<div class="riga" role="tab">
					<div class="lead col-sm-3 list-title"><<allTrim(SaldiMag->Cod)>></div>
					<div class="lead col-sm-4 list-title"><<allTrim(SaldiMag->Des)>></div>							
					<div class="lead col-sm-2 list-title" style="text-align:right;"><<Transform(SaldiMag->Sum_Cons,"999999.99")>></div>
					<input type="number" step="0.01" class="lead col-sm-2 list-title border <<m.cTxtID>>" value="<<Ltrim(Transform(SaldiMag->_Qta,'999999.99'))>>" step="0.01" tabindex="<<m.nTabIndex>>">
				</div>
			</div>
		EndText
		nTabIndex = m.nTabIndex + 2

	EndScan
Endif

TEXT to cScript textmerge noshow flags 3
	jQuery("#<<This.wcIdBs>>").html(<<cLitteralJS(m.cHTML)>>)
	var EventRequest = jQuery.proxy(FoxInCloud.EventRequest, FoxInCloud);
	jQuery("#<<This.wcIdBs>> div.panel").each(function(idx, elem){elem.addEventListener('click', function(event) {EventRequest(
			  "DOMEvent"
		  , event
		  , this
		  , jQuery(this).data("rowid")
		  , "<<this.wcID>>"
			)}, true);});

	var mousedown = false;
	jQuery("#<<This.wcIdBs>> .<<m.cTxtID>>")
		.mousedown(function(){
    	mousedown = true;
		})
		.focus(function(event) {var row = this.parentElement.parentElement; !mousedown && EventRequest(
			  "DOMEvent"
		  , 'click'
		  , row
		  , jQuery(row).data('rowid')
		  , "<<this.wcID>>"
			);
			mousedown=false;
			})
		.blur(function(event) {EventRequest(
			  "DOMEvent"
		  , event
		  , this
		  , jQuery(this).val()
		  , "<<m.cTxtID>>"
			);});
ENDTEXT

thisForm.wcScriptJSadd(m.cScript)

*!*	=RegLog("Refresh_ End",ThisForm.Name)

Gravatar is a globally recognized avatar based on your email address. re: Problem inserting number with decimals in list
  FoxInCloud Support - Thierry N.
  Michele
  Oct 26, 2021 @ 02:54am

Ciao Michele,

IMHO, we have a decimal point mismatch between client and server. These issues are always difficult to pin down (like date-time issues), so let's be patient in stepping through all the steps involved in the full client <> server process.

On server side, abPoint = abSet('point', '') resets the decimal point to its default '.' and resets back to the previous value when procedure ends.
The value seems to display OK in the browser, albeit with the decimal point localized to ','.

The first question is: when you change and validate a new value including a decimal point, what value is sent to the server?
Can you check the blur request in the browser's network panel and share a screenshot?

Gravatar is a globally recognized avatar based on your email address. re: Problem inserting number with decimals in list
  Michele
  FoxInCloud Support - Thierry N.
  Oct 26, 2021 @ 03:02am

Gravatar is a globally recognized avatar based on your email address. re: Problem inserting number with decimals in list
  FoxInCloud Support - Thierry N.
  Michele
  Oct 26, 2021 @ 05:38am

Please check the value that goes into .ControlSource : set a breakpoint into awtxt.lostFocusInet():

lparameters tuValue

set step on && ? m.tuValue

return thisForm.LostFocusInet(;
	  m.this;
	, this.InteractiveChangeInet(@m.tuValue);
	, m.tuValue;
	)

Check tuValue on set step on then step through the code until you reach awTxt.wuValue(); check tuValue there.

Gravatar is a globally recognized avatar based on your email address. re: Problem inserting number with decimals in list
  Michele
  FoxInCloud Support - Thierry N.
  Oct 26, 2021 @ 06:23am

At this row in interactivechangeinet

* Le cas échéant, typer la valeur selon le contrôle
tuValue = Iif(lMethod(m.toMember, 'wuValue');
	, toMember.wuValue(m.tuValue);
	, m.tuValue;
	)

tuValue enter 0.24 and exit 24

Problem is here:

case m.lcTypeSrce == 'C'
	tuValue = upper(alltrim(m.tuValue))
	if m.lcTypeDest $ 'YNI'

		* {fr} Normaliser le point décimal éventuel, supprimer les séparateurs de milliers
		lcPoint = set("Point")
		lcSeparator = set("Separator")
		lcChars = m.lcSeparator + space(1) + set("Currency", 1) + '$'
		tuValue = iif(m.lcSeparator == '.';
			, chrtran(m.tuValue, m.lcChars, '');
			, chrtran(m.tuValue, '.' + m.lcChars, m.lcPoint);
			)

In abdev.prg tuValue is 0.32 and you transform if in '', but here "." is not separator, but point...

Gravatar is a globally recognized avatar based on your email address. re: Problem inserting number with decimals in list
  FoxInCloud Support - Thierry N.
  Michele
  Oct 26, 2021 @ 10:25am

Thanks, I can reproduce:

set point to ','
set separator to '.'
? uValue('.14', 'N') && 14,00

Will get back with a fix

Gravatar is a globally recognized avatar based on your email address. re: Problem inserting number with decimals in list
  FoxInCloud Support - Thierry N.
  Michele
  Oct 30, 2021 @ 09:27am

Ciao Michele,

Here is the fix

1- modify command abDev.prg, replace the whole function uValue code by:

* ------------------------------------
function uValue && {en} Value converted to a specified varType (AKA type coersion) {fr} Valeur convertie selon un varType spécifié (coercition de type)
lparameters ;
  tuValue; && {en} Source Value {fr} Valeur source
, tcTypeDest; && {en} Expected Value Type according to VarType() codes {fr} Type de valeur attendu selon codification de la fonction VFP VarType()
, tlNlitt; && [.F.] {en} Literal numeric string {fr} Littéral si chaîne numérique && 2021-10-30 thn -- {FiC V 3.0.0-beta.5} {en} added

&& {fr} /!\ pourrait être simplifiée et optimisée avec Cast()

local luResult;
, llResult;
, lcTypeSrce;
, lcTypeDest;
, lcPoint, lcSeparator, lcChars;

#if .f. && {fr} Vartype() VFP9
	C && {fr} Character, Memo, Varchar, Varchar (Binary)
	D && {fr} Date
	G && {fr} General
	L && {fr} Logical
	N && {fr} Numeric, Float, Double, or Integer
	O && {fr} Object
	Q && {fr} Blob, Varbinary
	T && {fr} DateTime
	U && {fr} Unknown or variable does not exist
	X && .NULL.
	Y && {fr} Currency
	I && {fr} Integer && {fr} support additionnel
#endif

luResult = .null.

do case
case !(.T.;
 and Vartype(m.tcTypeDest) == 'C';
 and varSet(@m.lcTypeDest, Upper(Alltrim(m.tcTypeDest)));
 and Lenc(m.lcTypeDest) = 1;
 and m.lcTypeDest $ 'CDGLNOQTUXYI';
 )
	assert .F. message cAssertMsg(textmerge("Spécification de type non supportée : <<cLitteral(m.tcTypeDest)>>"))
 
case varSet(@m.lcTypeSrce, Vartype(m.tuValue)) and !m.lcTypeSrce $ 'CNYLDTX'
	assert .F. message cAssertMsg(textmerge("Type de valeur non supportée : <<cLitteral(m.lcTypeSrce)>>"))

case m.lcTypeDest == m.lcTypeSrce
	luResult = m.tuValue

case m.lcTypeSrce == 'C'
	tuValue = upper(alltrim(m.tuValue))
	if m.lcTypeDest $ 'YNI'

		* {fr} Normaliser le point décimal éventuel, supprimer les séparateurs de milliers
		lcPoint = set("Point")
		lcSeparator = set("Separator")
		lcChars = m.lcSeparator + space(1) + set("Currency", 1) + '$'
		tuValue = ICase(;
			lTrue(m.tlNlitt),;
			  strtran(m.tuValue, '.', m.lcPoint),; && 2021-10-30 thn -- {FiC V 3.0.0-beta.5} {en} added for https://support.west-wind.com/Thread66D0H3XML.wwt
			m.lcSeparator == '.',;
			  chrtran(m.tuValue, m.lcChars, ''),;
			  chrtran(m.tuValue, '.' + m.lcChars, m.lcPoint);
			)
		assert occurs(m.lcPoint, m.tuValue) <= 1 message cAssertMsg(textmerge([Plus d'un séparateur décimal dans le nombre <<m.tuValue>>]))
	endif

	luResult = icase(;
		m.lcTypeDest == 'N', val(m.tuValue),;
		m.lcTypeDest == 'Y', ntom(val(m.tuValue)),;
		m.lcTypeDest == 'I', int(val(m.tuValue)),;
		m.lcTypeDest == 'L', icase(;
			inlist(m.tuValue, 'T', '.T.', 'VRAI', 'TRUE'),;
				.t.,;
			empty(m.tuValue) or inlist(m.tuValue, 'F', '.F.', 'FAUX', 'FALSE'),;
				.f.,;
				evaluate(m.tuValue);
				),;
		m.lcTypeDest $ 'DT', iif(left(m.tuValue, 1) = '{', evaluate(m.tuValue), uValue_TD(m.tuValue, m.lcTypeDest)),;
		.null.)
	if m.lcTypeDest $ 'DT' && {fr} Ctod() et Ctot() peuvent produire un résultat invalide
		try
			dtoc(m.luResult)
		catch
			luResult = iif(m.lcTypeDest == 'D', {}, {/:})
		endtry
	endif

case m.lcTypeSrce == 'N'
	luResult = icase(;
		m.lcTypeDest == 'C', transform(m.tuValue),;
		m.lcTypeDest == 'I', int(m.tuValue),;
		m.lcTypeDest == 'Y', ntom(m.tuValue),;
		m.lcTypeDest == 'L', m.tuValue != 0,;
		.null.)

case m.lcTypeSrce $ 'DT'
	luResult = icase(;
		m.lcTypeDest == 'C', cLitteral(m.tuValue),; && {fr} mieux que Cast()
		m.lcTypeDest == 'D', ttod(m.tuValue),;
		m.lcTypeDest == 'T', dtot(m.tuValue),;
		.null.)

case m.lcTypeSrce == 'L'
	luResult = icase(;
		m.lcTypeDest == 'C', cLitteral(m.tuValue),;
		m.lcTypeDest $ 'NI', iif(m.tuValue, 1, 0),;
		.null.)

case m.lcTypeSrce == 'Y'
	luResult = icase(;
		m.lcTypeDest == 'C', transform(m.tuValue),;
		m.lcTypeDest == 'N', mton(m.tuValue),;
		m.lcTypeDest == 'I', int(mton(m.tuValue)),;
		m.lcTypeDest == 'L', not m.tuValue = ntom(0),;
		.null.)

case m.lcTypeSrce == 'X'
	luResult = uEmpty(m.lcTypeDest)

endcase

return m.luResult
endfunc

2- modify class awtxt of aw method wuValue, replace the whole code by:

lparameters tuValue

tuValue = this.wuValueField(Iif(Vartype(m.tuValue) == 'C';
	, uValue(m.tuValue, Vartype(m.this.Value, .T.), .T.);
	, m.tuValue;
	))

tuValue = Iif(Vartype(m.tuValue) == 'C' and '!' $ this.Format;
	, Upper(m.tuValue);
	, m.tuValue;
	)

return m.tuValue
Gravatar is a globally recognized avatar based on your email address. re: Problem inserting number with decimals in list
  Michele
  FoxInCloud Support - Thierry N.
  Nov 2, 2021 @ 04:25am

It works. Thanks

© 1996-2024