Página 1 de 1

Retornar 2 e 2.555

Enviado: 26 Jul 2015 12:18
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.

Retornar 2 e 2.555

Enviado: 26 Jul 2015 13:50
por alxsts
Olá!

Tentou com Int() e Round()?

Retornar 2 e 2.555

Enviado: 27 Jul 2015 09:00
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

Retornar 2 e 2.555

Enviado: 27 Jul 2015 15:50
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

Retornar 2 e 2.555

Enviado: 27 Jul 2015 18:11
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

Retornar 2 e 2.555

Enviado: 27 Jul 2015 23:20
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.

Retornar 2 e 2.555

Enviado: 28 Jul 2015 08:43
por sambomb
Qual o formato do campo?

Retornar 2 e 2.555

Enviado: 28 Jul 2015 12:14
por alxsts
Olá!

De onde está lendo isto? ADO Recordset?

Retornar 2 e 2.555

Enviado: 28 Jul 2015 16:12
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.