Retornar 2 e 2.555

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Retornar 2 e 2.555

Mensagem por JoséQuintas »

Código: Selecionar todos

PROCEDURE Main
   LOCAL nValue1 := 2.000, nValue2 := 2.555
   ? hb_ntos( nValue1 ), hb_ntos( nValue2 )
   ? hb_ValToExp( nValue1 ), hb_ValToExp( nValue2 )
   ? hb_ValToStr( nValue1 ), hb_ValToStr( nValue2 )
   ? Str( nValue1 ), Str( nValue2 )
   ? NTOc( nValue1 ), NToc( nValue2 )
   ? StrFormat( nValue1 ), StrFormat( nValue2 )
   ? ValToCharacter( nValue1 ), ValToCharacter( nValue2 )
   ? ValToPrgExp( nValue1 ), ValToPrgExp( nValue2 )
   RETURN
2.000 2.555
2.000 2.555
2.000 2.555
2.000 2.555
2 2

2.000 2.555
2.000 2.555

Alguma idéia se existe alguma função que retorne 2 e 2.555 ?

Tudo bem, criei a minha, mas será possível que tem tanta função no Harbour e nenhuma pra isso?

Motivo simples:
Um backup em SQL de 1 milhão de registros pode gerar três milhões de caracteres a mais por causa do ".00", contando apenas um único campo.
E se existir uma função pronta, deve ser mais rápida que a minha pra muitos registros.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
alxsts
Colaborador
Colaborador
Mensagens: 3092
Registrado em: 12 Ago 2008 15:50
Localização: São Paulo-SP-Brasil

Retornar 2 e 2.555

Mensagem por alxsts »

Olá!

Tentou com Int() e Round()?
[]´s
Alexandre Santos (AlxSts)
sambomb
Usuário Nível 3
Usuário Nível 3
Mensagens: 250
Registrado em: 24 Out 2008 17:02
Localização: Itaocara - RJ - Brasil

Retornar 2 e 2.555

Mensagem por sambomb »

Já tentou o Transform com máscara Z?
Transform()
Converts values to a PICTURE formatted character string.
Syntax
Transform( <xValue>, <cPicture> ) --> cFormattedString

Arguments
<xValue>
This is a value of data type Character, Date, Logic, Memo or Numeric to be formatted.
<cPicture>
This is a PICTURE formatting string defining the formatting rules (see below). Return
The function returns a character string holding the formatted value of <xValue>.
Description
Transform() is used to convert values of simple data types (C,D,L,M,N) to formatted character strings. Formatting rules are defined with the second parameter <cPicture>. This picture string may consist of characters defining a picture function, or characters defining a picture mask, or both. If picture function and mask are present in the picture string, the picture function must be first and the mask characters must be separated from the picture function by a single blank space.
Picture function
A picture function specifies formatting rules for the entire output string. It must begin with the @ sign followed by one or more letters listed in the table below:
Picture function characters Function Formatting rule
B Formats numbers left-justified
C Adds CR (credit) after positive numbers
D Formats dates in SET DATE format
E Formats dates and numbers in British format
L Pads numbers with zeros instead of blank spaces
R Nontemplate characters are inserted
X Adds DB (debit) after negative numbers
Z Formats zeros as blanks
( Encloses negative numbers in parentheses
! Converts alphabetic characters to uppercase

Picture mask
The picture mask must be separated by a single space from the picture function. When no picture function is used, the picture string is identical with the picture mask. The mask defines formatting rules for individual characters in the output string. Characters from the following table can be used. The position of a character of a picture mask specifies formatting for the character of the output string at the same position. An exception is the @R function which causes non-mask characters being inserted into the output string.
Picture mask characters Charactere Formatting rule
A,N,X,9,# Formats digits for any data type
L Formats logicals as "T" or "F"
Y Formats logicals as "Y" or "N"
! Converts alphabetic characters to uppercase
$ Adds a dollar sign in place of a leading space in a number
* Adds an asterisk in place of a leading space in a number
. Specifies a decimal point position
, Specifies a comma position
Imagem

Rca Sistemas - Itaocara - RJ
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Retornar 2 e 2.555

Mensagem por JoséQuintas »

Tentei, mas só aceita pros zeros à esquerda.
Acabei criando esta função, pra um uso específico.

Código: Selecionar todos

FUNCTION NumberSql( xValue )
   xValue := Ltrim( Str( xValue ) )
   IF "." $ xValue
      DO WHILE Right( xValue, 1 ) == "0"
         xValue := Substr( xValue, 1, Len( xValue ) - 1 )
      ENDDO
      IF Right( xValue, 1 ) == "."
         xValue := Substr( xValue, 1, Len( xValue ) - 1 )
      ENDIF
   ENDIF
   RETURN xValue
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
sambomb
Usuário Nível 3
Usuário Nível 3
Mensagens: 250
Registrado em: 24 Out 2008 17:02
Localização: Itaocara - RJ - Brasil

Retornar 2 e 2.555

Mensagem por sambomb »

Qual o tipo do campo que você está armazenando isso no SQL?
Porque até onde eu sei o SQL grava apenas os números necessários...

http://www.w3schools.com/sql/sql_datatypes.asp
Imagem

Rca Sistemas - Itaocara - RJ
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Retornar 2 e 2.555

Mensagem por JoséQuintas »

Estou usando pra gerar o backup em SQL.
Pra restaurar não faz diferença, mas deixa o arquivo de backup menor.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
sambomb
Usuário Nível 3
Usuário Nível 3
Mensagens: 250
Registrado em: 24 Out 2008 17:02
Localização: Itaocara - RJ - Brasil

Retornar 2 e 2.555

Mensagem por sambomb »

Qual o formato do campo?
Imagem

Rca Sistemas - Itaocara - RJ
alxsts
Colaborador
Colaborador
Mensagens: 3092
Registrado em: 12 Ago 2008 15:50
Localização: São Paulo-SP-Brasil

Retornar 2 e 2.555

Mensagem por alxsts »

Olá!

De onde está lendo isto? ADO Recordset?
[]´s
Alexandre Santos (AlxSts)
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Retornar 2 e 2.555

Mensagem por JoséQuintas »

Isso. Mas valores com duas decimais, vém como 2.00.
Nenhum problema, é só pra reduzir o tamanho mesmo, do arquivo .SQL correspondente ao backup.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Responder