Two digits after the decimal point in a real number in Pascal - number-formatting

So for an example i have a real number let's say 17.4578 but i want to display it in pascal with only two digits after the point so it's 17.45.
What do i write in my program?

Write(17.4578:0:2)
Will display number 17.46
Generally, arguments look like this → Value : field_width : decimal_field_width
For more info click here

This would work. However, if this is the last line of code always remember a readln at the end.
Writeln(17.4578:0:2)
This would lead to 17.46 because it rounds up as it is followed by a 7.
Hope this helps

Use :0:2 at the end of Real number:
writeln(17.4578:0:2)

Related

Extracting Portions of String

I have a field with the following types of string
X000233756_9981900025_201901_EUR_/
I firstly need to take take the characters to the left of the first _
Secondly I need to take the characters between the first and 2nd _
First _ is CHARINDEX('_',[Line_Item_Text],1) AS Position_1
Second _ is CHARINDEX('_',[Line_Item_Text],CHARINDEX('_',[Line_Item_Text],1)+1) AS Position_2
I was then expecting to be able to do
left([Line_Item_Text],CHARINDEX('_',[Line_Item_Text],1)-1) AS Data_1
Substring([Line_Item_Text],CHARINDEX('_',[Line_Item_Text],1)+1),CHARINDEX('_',[Line_Item_Text],CHARINDEX('_',[Line_Item_Text],1)+1) - CHARINDEX('_',[Line_Item_Text],1)+1)) AS Data_2"
Which should give me
X000233756
9981900025
But getting errors with incorrect number of functions when I start adding and subtracting from CHARINDEX Function.
Any ideas where I am going wrong?
TIA
Geoff
Actually, using the base string functions here is going to be an ugly nightmare. You might find that STRING_SPLIT along with some clever logic might be easier:
SELECT value
FROM STRING_SPLIT('X000233756_9981900025_201901_EUR_', '_')
WHERE LEN(value) > 6 AND NOT value LIKE '[A-Z]%';
This answer assumes that the third and fourth components would always be a 6 digit date and 3 letter currency code, and that the first (but not second) component would always start with some letter.
Demo

Error in hexadecimal conversion to base58-btc

I am using the conversion algorithm of http://lenschulwitz.com/base58 , this perl code.
MANY GOOD CONVERSIONS, AS: 18e559fc6cb0e8de2ce8b50007d474a0d886208e698a07948671e0df520c1525 was converted to 2gBdDRXoLPEhgf9Zd7zw5ujK1qcoPZoendBQJ22VjgqS, all 44 digits.
BAD CONVERSION: 0ab3de5e16675aeb0c4831f5218901fec56f39cc8ad16e5559be4a0ee211f5d0 was converted to in9v3fi1cntD6ERD6QryMJq4r5BncjYZ32xZA6Uj4ST, 43 digits!
other BAD: 00000000000000000000000000000000000000000000000000000000000000d0 to 11111111111111111111111111111114b
What is wrong with the Perl code?
I can use some kind of padding in base58-btc?
PS: I can use something as sudo apt-get install libbase58-0 that is reliable at UBUNTU... But need a Perl interface for it.
Rather than debugging that poorly laid-out code, I suggest that you install Encode::Base58
or
Encode::Base58::GMP
Both of those modules have maintainers who will answer questions if you find you are getting incorrect results
Tested with other conversors, as bs58 js lib, all producing same and consistent results.
It seems XY problem... perhaps the real question is "base58 bitcoin use fixed size representation?" Can I use something as pad 1s?
But it is also part of the answer, not edited the question (reverted) and proced an answer.
... It is a conversion between "incompatible" bases (!), so I think is impossible
... 58=2*29 is not a multiple of 16=2^4... only when digits are multiple of 2... But:
base50("E") = hex("0D"); base58("1E") = hex("000D"); ... the number of padding digits are converted as multiple...
what the problem of cut/add for padding? base50("E") = hex("D"); base58("1E") = hex("D"); base50("E")=hex("000000D"); base50("1111111111E")=hex("D"); ... Not seems a problem, so padding-algorithm (fill 0s or 1s) can be used.
SOLUTION: ok, lets pad, fill 1s when converted have less than 44 digits.

Ogg metadata - Vorbis Comment end

I want to implement a class to read vorbis comments. I know that a field will start with a field name, followed by an equal sign and the value. But how does it end? Documentation makes me think that a semicolon will end the field but I checked an ogg file with a hex editor and I cannot see any.
This is how I think it should look like in a file :
TITLE=MY SUPER TITLE;
The field name is title, followed by the equals sign and then the value is MY SUPER TITLE. And finally the semicolon to end the field.
But instead inside my file, the fields look like this :
TITLE=MY SUPER TITLE....
It's almost as above but there is no semicolon. The .'s are characters that cannot be displayed. I thought okay, it seems like the dots represent a value that will say "this is the end of the field!!" but they are almost always different. I noticed that there are always exactly 4 dots. The first dot has always a different value. The other free have usually a value of 0. But not always...
My question now, how does a field end? How do I read this comment?
Also, yeah I know that there are libraries and that I should use them instead of reinventing the wheel over and over again. I will use libraries later but first I want to know how to do it myself. Educational purpose only.
Each field is preceded by a little-endian 32-bit integer that indicates the number of bytes to read. You then convert the bytes to a string via UTF8.
See NVorbis' implementation (LoadComments(...)) for details.

Regular Expression for number.(space), objective-c

I have an NSArray of lines (objective-c iphone), and I'm trying to find the line which starts with a number, followed by a dot and a space, but can have any number of spaces (including none) before it, and have any text following it eg:
1. random text
2. text random
3.
what regular expression would I use to get this? (I'm trying to learn it, and I needed the above expression anyway, so I thought I'd use it as an example)
With C#:
#"^ *[0-9]+\. "
It doesn't check for the presence of something after the ., so this is legal:
1.(space)
If you delete the # and escape the \ it should work with other languages (it is pretty "down-to-earth" as RegExpes go)
I may suggest (Perl-compatible regexp):
^\s*\d+\.\s
At the beginning of a line:
Any number (0-n) of spaces
One or more digits
A dot
A space
Something like
^\s*\d+\.
But it depends on the language.
/^\s*[0-9]+\.\s+/
would be my guess providing you don't have any space before the number

How should I handle digits from different sets of UNICODE digits in the same string?

I am writing a function that transliterates UNICODE digits into ASCII digits, and I am a bit stumped on what to do if the string contains digits from different sets of UNICODE digits. So for example, if I have the string "\x{2463}\x{24F6}" ("④⓶"). Should my function
return 42?
croak that the string contains mixed sets?
carp that the string contains mixed sets and return 42?
give the user an additional argument to specify one of the three above behaviours?
do something else?
Your current function appears to do #1.
I suggest that you should also write another function to do #4, but only when the requirement appears, and not before .
I'm sure Joel wrote about "premature implementation" in a blog article sometime recently, but I can't find it.
I'm not sure I see a problem.
You support numeric conversion from a range of scripts, which is to say, you are aware of the Unicode codepoints for their numeric characters.
If you find an unknown codepoint in your input data, it is an error.
It is up to you what you do in the event of an error; you may insert a space or underscore, or you may abort conversion. What you would do will depend on the environment in which your function executes; it is not something we can tell you.
My initial thought was #4; strictly based on the fact that I like options. However, I changed my mind, when I viewed your function.
The purpose of the function seems to be, simply, to get the resulting digits 0..9. Users may find it useful to send in mixed sets (a feature :) . I'll use it.
If you ever have to handle input in bases greater than 10, you may end up having to treat many variants on the first 6 letters of the Latin alphabet ('ABCDEF') as digits in all their forms.