27. november 2003 - 10:36Der er
22 kommentarer og 2 løsninger
Formatering af tal
Hej.
Jeg skal på en rapport udskrive nogle tal, men kan ikke helt få formateringen til at passe. Det burde være let, men volder alligevel problemer.
Som det er nu har jeg nedenstående format på min textbox:
#.##0,00" DKK";\-#.##0,00" DKK"
Eneste problem er så at jeg gerne vil bytte om på punktum og komma. Det burde jo være ret let, men nej. Hvis jeg ændrer det til #,##0.00" DKK";\-#,##0.00" DKK" og trykker på Enter, så står der lige pludselig #,000\.00" DKK";\-#,000\.00" DKK" og nu passer formateringen derfor slet ikke længere.
Eksempler:
68.252,58 skal ændres til 68,252.58 12,00 skal ændre til 12.00
Efter ti år i London, Madrid, Paris og Utrecht kommer Sabios AI-fokuserede program af arrangementer om kundeoplevelser, ‘Disrupt’, for første gang til Danmark.
snowball, your comment to mlhave! If you use "fusk" then you will more than likley end up with the same format for all languages. So by using the PC's regional settings does exactly what you want. Or have I missunderstood your comment? "...så derfor skal det IKKE udskrives ens hver gang."!!
terry: I can't change the regional settings because then many other things will be changed besides the fields on my report. A solution might be to just change the regional settings at the time of report creation, and then change it back again when Access has created the report. Is that possible in Access?
Isn't it possible to add a "dummy" field to the report, give it the value of the original field, do a "string replace" so the dummy field has the correct format, hide the original field and at last show the "dummy" field !?
I have never had the need to change the regional settings in Access so I cant answer that. But what I dont understand is you say "...så derfor skal det IKKE udskrives ens hver gang."
IF it is NOT to be printed the same for each language then what decides HOW th ereport i sto be printed? Or is it to be the same for each language?
It is because I can print the report in several different languages, and all countrys dont use the same character for decimals and for thousand seperator. Fx. here in Denmark we write like this: 12.345,67kr. but in England they write like this: 12,345.67kr.
How do you decide when you have to print the report in Danish or English?
I still suggest you use the regional settings. Otherwise you will need to converting the currency field to text and then convert your characters , and . to what ever you want depending on the language. This could be done in a query wich calls a function and then use the query in the report.
terry: I can now see that it's not quite true what I've been telling you guys, sorry. The database this question is based on is a database I received sortly before I made this question, and I didn't have the full overview of the complete database - but I do now.
There is only 1 report, and that report will always be printed in english.
So, I think the best solution is to do what I mentioned in my comment 27/11-2003 11:29:22 about the "string replace" function and what you (terry) mentioned in your comment 28/11-2003 17:54:46. I would like to avoid changeing the reginal settings.
Terry, can you make an query/funcion example that changes , to . and vice versa ?
I can more than likley make a function which converts a danish formatted text to english, but IF the regional settings are alreadt english it will not work correctly!
terry: I can't understand that it in Access apparently is so difficult to do a simple string replace, show the new value in a new textbox and hide the original textbox!? That's all I want right now, and I really can't see how it cannot be done because of the regional settings!?
lets say´the PC's regional settings are DK! lets take a number 123.456,78 and then I make a string replace where it ends up as you want it in English 123,456.78
OK thats great, but now you have a PC where the regional settings are English, but my routine doesnt know that, so the number is already formatted 123,456.78 but the string replace routine now goes and convertes it to 123.456,78 which is NOT what you want!
So it isnt just a "simple" string replace, it has to take into account how it is already formatted!
Anyway try looking at the function REPLACE, MID and LEN can also be used for this too.
You're right - I understand what you're talking about now ;)
But anyway, I know that all the PC's where this Access application will be used, has Danish regional settings, so it won't really be a problem.
I'm aware of the function you just mentioned. My problem is that I can't figure out how to get the text from a text field on a report and copy it to a new field. I've tried, but I can't get i working because I have very little knowledge about Access as a frontend ;)
Could you please make a quick example showing how to do it?
FormatNumber kan da næsten kun være en funktion når det er skrevet på den måde. Hvilket også bekræftes hvis man søger lidt på MSDN. Funktionen findes så åbenbart ikke i Access97 !?
Man kan snyde den ved at lave sin egen FormatNumber funktion som nedenstående:
Function FormatNumber(Num) FormatNumber = Format(Num, "#.##0,00") End Function
Problemet er så bare lige og finde det rigtige format. Den vil ikke godtage ovenstående, og hvis man bare skriver "0,00" så fjerner den tusindtals seperatoren.
Har fået det til at virke nu. Dog ikke direkte i query'en, men ved at ligge den formaterede værdi over i et nyt tekst felt.
Function FormatNumber(Num) FormatNumber = Format(Num, "#,##0.00") End Function
Function FormatGB(CurIN As Currency) As String Dim str As String Dim i As Integer
str = FormatNumber(CurIN) For i = 1 To Len(str) If Mid(str, i, 1) = "." Then Mid(str, i, 1) = "," Else If Mid(str, i, 1) = "," Then Mid(str, i, 1) = "." End If End If Next i str = str + " DKK" FormatGB = str End Function
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.